<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>2. Built-in Functions &mdash; Python v2.6.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.2 documentation" href="../index.html" />
    <link rel="up" title="The Python Standard Library" href="index.html" />
    <link rel="next" title="4. Built-in Constants" href="constants.html" />
    <link rel="prev" title="1. Introduction" href="intro.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="constants.html" title="4. Built-in Constants"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="intro.html" title="1. Introduction"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" accesskey="U">The Python Standard Library</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="built-in-functions">
<span id="built-in-funcs"></span><h1>2. Built-in Functions<a class="headerlink" href="#built-in-functions" title="Permalink to this headline">¶</a></h1>
<p>The Python interpreter has a number of functions built into it that are always
available.  They are listed here in alphabetical order.</p>
<dl class="function">
<dt id="abs">
<tt class="descname">abs</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#abs" title="Permalink to this definition">¶</a></dt>
<dd>Return the absolute value of a number.  The argument may be a plain or long
integer or a floating point number.  If the argument is a complex number, its
magnitude is returned.</dd></dl>

<dl class="function">
<dt id="all">
<tt class="descname">all</tt><big>(</big><em>iterable</em><big>)</big><a class="headerlink" href="#all" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if all elements of the <em>iterable</em> are true. Equivalent to:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">all</span><span class="p">(</span><span class="n">iterable</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">element</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">False</span>
    <span class="k">return</span> <span class="bp">True</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.5.</span></p>
</dd></dl>

<dl class="function">
<dt id="any">
<tt class="descname">any</tt><big>(</big><em>iterable</em><big>)</big><a class="headerlink" href="#any" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if any element of the <em>iterable</em> is true. Equivalent to:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">any</span><span class="p">(</span><span class="n">iterable</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">element</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">element</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">True</span>
    <span class="k">return</span> <span class="bp">False</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.5.</span></p>
</dd></dl>

<dl class="function">
<dt id="basestring">
<tt class="descname">basestring</tt><big>(</big><big>)</big><a class="headerlink" href="#basestring" title="Permalink to this definition">¶</a></dt>
<dd><p>This abstract type is the superclass for <a title="str" class="reference internal" href="#str"><tt class="xref docutils literal"><span class="pre">str</span></tt></a> and <a title="unicode" class="reference internal" href="#unicode"><tt class="xref docutils literal"><span class="pre">unicode</span></tt></a>. It
cannot be called or instantiated, but it can be used to test whether an object
is an instance of <a title="str" class="reference internal" href="#str"><tt class="xref docutils literal"><span class="pre">str</span></tt></a> or <a title="unicode" class="reference internal" href="#unicode"><tt class="xref docutils literal"><span class="pre">unicode</span></tt></a>. <tt class="docutils literal"><span class="pre">isinstance(obj,</span>
<span class="pre">basestring)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">isinstance(obj,</span> <span class="pre">(str,</span> <span class="pre">unicode))</span></tt>.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="bin">
<tt class="descname">bin</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#bin" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert an integer number to a binary string. The result is a valid Python
expression.  If <em>x</em> is not a Python <a title="int" class="reference internal" href="#int"><tt class="xref docutils literal"><span class="pre">int</span></tt></a> object, it has to define an
<a title="object.__index__" class="reference external" href="../reference/datamodel.html#object.__index__"><tt class="xref docutils literal"><span class="pre">__index__()</span></tt></a> method that returns an integer.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="bool">
<tt class="descname">bool</tt><big>(</big><span class="optional">[</span><em>x</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#bool" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a value to a Boolean, using the standard truth testing procedure.  If
<em>x</em> is false or omitted, this returns <a title="False" class="reference external" href="constants.html#False"><tt class="xref xref docutils literal"><span class="pre">False</span></tt></a>; otherwise it returns
<a title="True" class="reference external" href="constants.html#True"><tt class="xref xref docutils literal"><span class="pre">True</span></tt></a>. <a title="bool" class="reference internal" href="#bool"><tt class="xref docutils literal"><span class="pre">bool</span></tt></a> is also a class, which is a subclass of
<a title="int" class="reference internal" href="#int"><tt class="xref docutils literal"><span class="pre">int</span></tt></a>. Class <a title="bool" class="reference internal" href="#bool"><tt class="xref docutils literal"><span class="pre">bool</span></tt></a> cannot be subclassed further.  Its only
instances are <a title="False" class="reference external" href="constants.html#False"><tt class="xref xref docutils literal"><span class="pre">False</span></tt></a> and <a title="True" class="reference external" href="constants.html#True"><tt class="xref xref docutils literal"><span class="pre">True</span></tt></a>.</p>
<p id="index-326">
<span class="versionmodified">New in version 2.2.1.</span></p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>If no argument is given, this function returns <a title="False" class="reference external" href="constants.html#False"><tt class="xref xref docutils literal"><span class="pre">False</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="callable">
<tt class="descname">callable</tt><big>(</big><em>object</em><big>)</big><a class="headerlink" href="#callable" title="Permalink to this definition">¶</a></dt>
<dd>Return <a title="True" class="reference external" href="constants.html#True"><tt class="xref xref docutils literal"><span class="pre">True</span></tt></a> if the <em>object</em> argument appears callable,
<a title="False" class="reference external" href="constants.html#False"><tt class="xref xref docutils literal"><span class="pre">False</span></tt></a> if not.  If this
returns true, it is still possible that a call fails, but if it is false,
calling <em>object</em> will never succeed.  Note that classes are callable (calling a
class returns a new instance); class instances are callable if they have a
<a title="object.__call__" class="reference external" href="../reference/datamodel.html#object.__call__"><tt class="xref docutils literal"><span class="pre">__call__()</span></tt></a> method.</dd></dl>

<dl class="function">
<dt id="chr">
<tt class="descname">chr</tt><big>(</big><em>i</em><big>)</big><a class="headerlink" href="#chr" title="Permalink to this definition">¶</a></dt>
<dd>Return a string of one character whose ASCII code is the integer <em>i</em>.  For
example, <tt class="docutils literal"><span class="pre">chr(97)</span></tt> returns the string <tt class="docutils literal"><span class="pre">'a'</span></tt>. This is the inverse of
<a title="ord" class="reference internal" href="#ord"><tt class="xref docutils literal"><span class="pre">ord()</span></tt></a>.  The argument must be in the range [0..255], inclusive;
<a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> will be raised if <em>i</em> is outside that range. See
also <a title="unichr" class="reference internal" href="#unichr"><tt class="xref docutils literal"><span class="pre">unichr()</span></tt></a>.</dd></dl>

<dl class="function">
<dt id="classmethod">
<tt class="descname">classmethod</tt><big>(</big><em>function</em><big>)</big><a class="headerlink" href="#classmethod" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a class method for <em>function</em>.</p>
<p>A class method receives the class as implicit first argument, just like an
instance method receives the instance. To declare a class method, use this
idiom:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="o">...</span><span class="p">):</span> <span class="o">...</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">&#64;classmethod</span></tt> form is a function <a class="reference external" href="../glossary.html#term-decorator"><em class="xref">decorator</em></a> &#8211; see the description
of function definitions in <a class="reference external" href="../reference/compound_stmts.html#function"><em>Function definitions</em></a> for details.</p>
<p>It can be called either on the class (such as <tt class="docutils literal"><span class="pre">C.f()</span></tt>) or on an instance (such
as <tt class="docutils literal"><span class="pre">C().f()</span></tt>).  The instance is ignored except for its class. If a class
method is called for a derived class, the derived class object is passed as the
implied first argument.</p>
<p>Class methods are different than C++ or Java static methods. If you want those,
see <a title="staticmethod" class="reference internal" href="#staticmethod"><tt class="xref docutils literal"><span class="pre">staticmethod()</span></tt></a> in this section.</p>
<p>For more information on class methods, consult the documentation on the standard
type hierarchy in <a class="reference external" href="../reference/datamodel.html#types"><em>The standard type hierarchy</em></a>.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>Function decorator syntax added.</p>
</dd></dl>

<dl class="function">
<dt id="cmp">
<tt class="descname">cmp</tt><big>(</big><em>x</em>, <em>y</em><big>)</big><a class="headerlink" href="#cmp" title="Permalink to this definition">¶</a></dt>
<dd>Compare the two objects <em>x</em> and <em>y</em> and return an integer according to the
outcome.  The return value is negative if <tt class="docutils literal"><span class="pre">x</span> <span class="pre">&lt;</span> <span class="pre">y</span></tt>, zero if <tt class="docutils literal"><span class="pre">x</span> <span class="pre">==</span> <span class="pre">y</span></tt> and
strictly positive if <tt class="docutils literal"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span></tt>.</dd></dl>

<dl class="function">
<dt id="compile">
<tt class="descname">compile</tt><big>(</big><em>source</em>, <em>filename</em>, <em>mode</em><span class="optional">[</span>, <em>flags</em><span class="optional">[</span>, <em>dont_inherit</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#compile" title="Permalink to this definition">¶</a></dt>
<dd><p>Compile the <em>source</em> into a code or AST object.  Code objects can be executed
by an <a class="reference external" href="../reference/simple_stmts.html#exec"><tt class="xref docutils literal"><span class="pre">exec</span></tt></a> statement or evaluated by a call to <a title="eval" class="reference internal" href="#eval"><tt class="xref docutils literal"><span class="pre">eval()</span></tt></a>.
<em>source</em> can either be a string or an AST object.  Refer to the <a title="Abstract Syntax Tree classes and manipulation." class="reference external" href="ast.html#module-ast"><tt class="xref docutils literal"><span class="pre">ast</span></tt></a>
module documentation for information on how to work with AST objects.</p>
<p>The <em>filename</em> argument should give the file from which the code was read;
pass some recognizable value if it wasn&#8217;t read from a file (<tt class="docutils literal"><span class="pre">'&lt;string&gt;'</span></tt> is
commonly used).</p>
<p>The <em>mode</em> argument specifies what kind of code must be compiled; it can be
<tt class="docutils literal"><span class="pre">'exec'</span></tt> if <em>source</em> consists of a sequence of statements, <tt class="docutils literal"><span class="pre">'eval'</span></tt> if it
consists of a single expression, or <tt class="docutils literal"><span class="pre">'single'</span></tt> if it consists of a single
interactive statement (in the latter case, expression statements that
evaluate to something else than <tt class="xref docutils literal"><span class="pre">None</span></tt> will be printed).</p>
<p>The optional arguments <em>flags</em> and <em>dont_inherit</em> control which future
statements (see <span class="target" id="index-327"></span><a class="reference external" href="http://www.python.org/dev/peps/pep-0236"><strong>PEP 236</strong></a>) affect the compilation of <em>source</em>.  If neither
is present (or both are zero) the code is compiled with those future
statements that are in effect in the code that is calling compile.  If the
<em>flags</em> argument is given and <em>dont_inherit</em> is not (or is zero) then the
future statements specified by the <em>flags</em> argument are used in addition to
those that would be used anyway. If <em>dont_inherit</em> is a non-zero integer then
the <em>flags</em> argument is it &#8211; the future statements in effect around the call
to compile are ignored.</p>
<p>Future statements are specified by bits which can be bitwise ORed together to
specify multiple statements.  The bitfield required to specify a given feature
can be found as the <tt class="xref docutils literal"><span class="pre">compiler_flag</span></tt> attribute on the <tt class="xref docutils literal"><span class="pre">_Feature</span></tt>
instance in the <a title="Future statement definitions" class="reference external" href="__future__.html#module-__future__"><tt class="xref docutils literal"><span class="pre">__future__</span></tt></a> module.</p>
<p>This function raises <a title="exceptions.SyntaxError" class="reference external" href="exceptions.html#exceptions.SyntaxError"><tt class="xref docutils literal"><span class="pre">SyntaxError</span></tt></a> if the compiled source is invalid,
and <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> if the source contains null bytes.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When compiling a string with multi-line statements, line endings must be
represented by a single newline character (<tt class="docutils literal"><span class="pre">'\n'</span></tt>), and the input must
be terminated by at least one newline character.  If line endings are
represented by <tt class="docutils literal"><span class="pre">'\r\n'</span></tt>, use <a title="str.replace" class="reference external" href="stdtypes.html#str.replace"><tt class="xref docutils literal"><span class="pre">str.replace()</span></tt></a> to change them into
<tt class="docutils literal"><span class="pre">'\n'</span></tt>.</p>
</div>
<p>
<span class="versionmodified">Changed in version 2.3: </span>The <em>flags</em> and <em>dont_inherit</em> arguments were added.</p>
<p>
<span class="versionmodified">Changed in version 2.6: </span>Support for compiling AST objects.</p>
</dd></dl>

<dl class="function">
<dt id="complex">
<tt class="descname">complex</tt><big>(</big><span class="optional">[</span><em>real</em><span class="optional">[</span>, <em>imag</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#complex" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a complex number with the value <em>real</em> + <em>imag</em>*j or convert a string or
number to a complex number.  If the first parameter is a string, it will be
interpreted as a complex number and the function must be called without a second
parameter.  The second parameter can never be a string. Each argument may be any
numeric type (including complex). If <em>imag</em> is omitted, it defaults to zero and
the function serves as a numeric conversion function like <a title="int" class="reference internal" href="#int"><tt class="xref docutils literal"><span class="pre">int()</span></tt></a>,
<a title="long" class="reference internal" href="#long"><tt class="xref docutils literal"><span class="pre">long()</span></tt></a> and <a title="float" class="reference internal" href="#float"><tt class="xref docutils literal"><span class="pre">float()</span></tt></a>.  If both arguments are omitted, returns <tt class="docutils literal"><span class="pre">0j</span></tt>.</p>
<p>The complex type is described in <a class="reference external" href="stdtypes.html#typesnumeric"><em>Numeric Types &#8212; int, float, long, complex</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="delattr">
<tt class="descname">delattr</tt><big>(</big><em>object</em>, <em>name</em><big>)</big><a class="headerlink" href="#delattr" title="Permalink to this definition">¶</a></dt>
<dd>This is a relative of <a title="setattr" class="reference internal" href="#setattr"><tt class="xref docutils literal"><span class="pre">setattr()</span></tt></a>.  The arguments are an object and a
string.  The string must be the name of one of the object&#8217;s attributes.  The
function deletes the named attribute, provided the object allows it.  For
example, <tt class="docutils literal"><span class="pre">delattr(x,</span> <span class="pre">'foobar')</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">del</span> <span class="pre">x.foobar</span></tt>.</dd></dl>

<dl class="function">
<dt>
<tt class="descname">dict</tt><big>(</big><span class="optional">[</span><em>arg</em><span class="optional">]</span><big>)</big></dt>
<dd><p>Create a new data dictionary, optionally with items taken from <em>arg</em>.
The dictionary type is described in <a class="reference external" href="stdtypes.html#typesmapping"><em>Mapping Types &#8212; dict</em></a>.</p>
<p>For other containers see the built in <a title="list" class="reference internal" href="#list"><tt class="xref docutils literal"><span class="pre">list</span></tt></a>, <a title="set" class="reference external" href="stdtypes.html#set"><tt class="xref docutils literal"><span class="pre">set</span></tt></a>, and
<a title="tuple" class="reference internal" href="#tuple"><tt class="xref docutils literal"><span class="pre">tuple</span></tt></a> classes, and the <a title="High-performance datatypes" class="reference external" href="collections.html#module-collections"><tt class="xref docutils literal"><span class="pre">collections</span></tt></a> module.</p>
</dd></dl>

<dl class="function">
<dt id="dir">
<tt class="descname">dir</tt><big>(</big><span class="optional">[</span><em>object</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#dir" title="Permalink to this definition">¶</a></dt>
<dd><p>Without arguments, return the list of names in the current local scope.  With an
argument, attempt to return a list of valid attributes for that object.</p>
<p>If the object has a method named <tt class="xref docutils literal"><span class="pre">__dir__()</span></tt>, this method will be called and
must return the list of attributes. This allows objects that implement a custom
<a title="object.__getattr__" class="reference external" href="../reference/datamodel.html#object.__getattr__"><tt class="xref docutils literal"><span class="pre">__getattr__()</span></tt></a> or <a title="object.__getattribute__" class="reference external" href="../reference/datamodel.html#object.__getattribute__"><tt class="xref docutils literal"><span class="pre">__getattribute__()</span></tt></a> function to customize the way
<a title="dir" class="reference internal" href="#dir"><tt class="xref docutils literal"><span class="pre">dir()</span></tt></a> reports their attributes.</p>
<p>If the object does not provide <tt class="xref docutils literal"><span class="pre">__dir__()</span></tt>, the function tries its best to
gather information from the object&#8217;s <tt class="xref docutils literal"><span class="pre">__dict__</span></tt> attribute, if defined, and
from its type object.  The resulting list is not necessarily complete, and may
be inaccurate when the object has a custom <a title="object.__getattr__" class="reference external" href="../reference/datamodel.html#object.__getattr__"><tt class="xref docutils literal"><span class="pre">__getattr__()</span></tt></a>.</p>
<p>The default <a title="dir" class="reference internal" href="#dir"><tt class="xref docutils literal"><span class="pre">dir()</span></tt></a> mechanism behaves differently with different types of
objects, as it attempts to produce the most relevant, rather than complete,
information:</p>
<ul class="simple">
<li>If the object is a module object, the list contains the names of the module&#8217;s
attributes.</li>
<li>If the object is a type or class object, the list contains the names of its
attributes, and recursively of the attributes of its bases.</li>
<li>Otherwise, the list contains the object&#8217;s attributes&#8217; names, the names of its
class&#8217;s attributes, and recursively of the attributes of its class&#8217;s base
classes.</li>
</ul>
<p>The resulting list is sorted alphabetically.  For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">struct</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">()</span>   <span class="c"># doctest: +SKIP</span>
<span class="go">[&#39;__builtins__&#39;, &#39;__doc__&#39;, &#39;__name__&#39;, &#39;struct&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">(</span><span class="n">struct</span><span class="p">)</span>   <span class="c"># doctest: +NORMALIZE_WHITESPACE</span>
<span class="go">[&#39;Struct&#39;, &#39;__builtins__&#39;, &#39;__doc__&#39;, &#39;__file__&#39;, &#39;__name__&#39;,</span>
<span class="go"> &#39;__package__&#39;, &#39;_clearcache&#39;, &#39;calcsize&#39;, &#39;error&#39;, &#39;pack&#39;, &#39;pack_into&#39;,</span>
<span class="go"> &#39;unpack&#39;, &#39;unpack_from&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Foo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">__dir__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="p">[</span><span class="s">&quot;kan&quot;</span><span class="p">,</span> <span class="s">&quot;ga&quot;</span><span class="p">,</span> <span class="s">&quot;roo&quot;</span><span class="p">]</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="go">[&#39;ga&#39;, &#39;kan&#39;, &#39;roo&#39;]</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Because <a title="dir" class="reference internal" href="#dir"><tt class="xref docutils literal"><span class="pre">dir()</span></tt></a> is supplied primarily as a convenience for use at an
interactive prompt, it tries to supply an interesting set of names more than it
tries to supply a rigorously or consistently defined set of names, and its
detailed behavior may change across releases.  For example, metaclass attributes
are not in the result list when the argument is a class.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="divmod">
<tt class="descname">divmod</tt><big>(</big><em>a</em>, <em>b</em><big>)</big><a class="headerlink" href="#divmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Take two (non complex) numbers as arguments and return a pair of numbers
consisting of their quotient and remainder when using long division.  With mixed
operand types, the rules for binary arithmetic operators apply.  For plain and
long integers, the result is the same as <tt class="docutils literal"><span class="pre">(a</span> <span class="pre">//</span> <span class="pre">b,</span> <span class="pre">a</span> <span class="pre">%</span> <span class="pre">b)</span></tt>. For floating point
numbers the result is <tt class="docutils literal"><span class="pre">(q,</span> <span class="pre">a</span> <span class="pre">%</span> <span class="pre">b)</span></tt>, where <em>q</em> is usually <tt class="docutils literal"><span class="pre">math.floor(a</span> <span class="pre">/</span> <span class="pre">b)</span></tt>
but may be 1 less than that.  In any case <tt class="docutils literal"><span class="pre">q</span> <span class="pre">*</span> <span class="pre">b</span> <span class="pre">+</span> <span class="pre">a</span> <span class="pre">%</span> <span class="pre">b</span></tt> is very close to
<em>a</em>, if <tt class="docutils literal"><span class="pre">a</span> <span class="pre">%</span> <span class="pre">b</span></tt> is non-zero it has the same sign as <em>b</em>, and <tt class="docutils literal"><span class="pre">0</span> <span class="pre">&lt;=</span> <span class="pre">abs(a</span> <span class="pre">%</span> <span class="pre">b)</span>
<span class="pre">&lt;</span> <span class="pre">abs(b)</span></tt>.</p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>Using <a title="divmod" class="reference internal" href="#divmod"><tt class="xref docutils literal"><span class="pre">divmod()</span></tt></a> with complex numbers is deprecated.</p>
</dd></dl>

<dl class="function">
<dt id="enumerate">
<tt class="descname">enumerate</tt><big>(</big><em>sequence</em><span class="optional">[</span>, <em>start=0</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#enumerate" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an enumerate object. <em>sequence</em> must be a sequence, an
<a class="reference external" href="../glossary.html#term-iterator"><em class="xref">iterator</em></a>, or some other object which supports iteration.  The
<a title="next" class="reference internal" href="#next"><tt class="xref docutils literal"><span class="pre">next()</span></tt></a> method of the iterator returned by <a title="enumerate" class="reference internal" href="#enumerate"><tt class="xref docutils literal"><span class="pre">enumerate()</span></tt></a> returns a
tuple containing a count (from <em>start</em> which defaults to 0) and the
corresponding value obtained from iterating over <em>iterable</em>.
<a title="enumerate" class="reference internal" href="#enumerate"><tt class="xref docutils literal"><span class="pre">enumerate()</span></tt></a> is useful for obtaining an indexed series: <tt class="docutils literal"><span class="pre">(0,</span> <span class="pre">seq[0])</span></tt>,
<tt class="docutils literal"><span class="pre">(1,</span> <span class="pre">seq[1])</span></tt>, <tt class="docutils literal"><span class="pre">(2,</span> <span class="pre">seq[2])</span></tt>, .... For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">season</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">([</span><span class="s">&#39;Spring&#39;</span><span class="p">,</span> <span class="s">&#39;Summer&#39;</span><span class="p">,</span> <span class="s">&#39;Fall&#39;</span><span class="p">,</span> <span class="s">&#39;Winter&#39;</span><span class="p">]):</span>
<span class="gp">... </span>    <span class="k">print</span> <span class="n">i</span><span class="p">,</span> <span class="n">season</span>
<span class="go">0 Spring</span>
<span class="go">1 Summer</span>
<span class="go">2 Fall</span>
<span class="go">3 Winter</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
<p>
<span class="versionmodified">New in version 2.6: </span>The <em>start</em> parameter.</p>
</dd></dl>

<dl class="function">
<dt id="eval">
<tt class="descname">eval</tt><big>(</big><em>expression</em><span class="optional">[</span>, <em>globals</em><span class="optional">[</span>, <em>locals</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#eval" title="Permalink to this definition">¶</a></dt>
<dd><p>The arguments are a string and optional globals and locals.  If provided,
<em>globals</em> must be a dictionary.  If provided, <em>locals</em> can be any mapping
object.</p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>formerly <em>locals</em> was required to be a dictionary.</p>
<p>The <em>expression</em> argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the <em>globals</em> and <em>locals</em>
dictionaries as global and local namespace.  If the <em>globals</em> dictionary is
present and lacks &#8216;__builtins__&#8217;, the current globals are copied into <em>globals</em>
before <em>expression</em> is parsed.  This means that <em>expression</em> normally has full
access to the standard <a title="The module that provides the built-in namespace." class="reference external" href="__builtin__.html#module-__builtin__"><tt class="xref docutils literal"><span class="pre">__builtin__</span></tt></a> module and restricted environments are
propagated.  If the <em>locals</em> dictionary is omitted it defaults to the <em>globals</em>
dictionary.  If both dictionaries are omitted, the expression is executed in the
environment where <a title="eval" class="reference internal" href="#eval"><tt class="xref docutils literal"><span class="pre">eval()</span></tt></a> is called.  The return value is the result of
the evaluated expression. Syntax errors are reported as exceptions.  Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="mf">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="nb">eval</span><span class="p">(</span><span class="s">&#39;x+1&#39;</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<p>This function can also be used to execute arbitrary code objects (such as
those created by <a title="compile" class="reference internal" href="#compile"><tt class="xref docutils literal"><span class="pre">compile()</span></tt></a>).  In this case pass a code object instead
of a string.  If the code object has been compiled with <tt class="docutils literal"><span class="pre">'exec'</span></tt> as the
<em>kind</em> argument, <a title="eval" class="reference internal" href="#eval"><tt class="xref docutils literal"><span class="pre">eval()</span></tt></a>&#8216;s return value will be <tt class="xref docutils literal"><span class="pre">None</span></tt>.</p>
<p>Hints: dynamic execution of statements is supported by the <a class="reference external" href="../reference/simple_stmts.html#exec"><tt class="xref docutils literal"><span class="pre">exec</span></tt></a>
statement.  Execution of statements from a file is supported by the
<a title="execfile" class="reference internal" href="#execfile"><tt class="xref docutils literal"><span class="pre">execfile()</span></tt></a> function.  The <a title="globals" class="reference internal" href="#globals"><tt class="xref docutils literal"><span class="pre">globals()</span></tt></a> and <a title="locals" class="reference internal" href="#locals"><tt class="xref docutils literal"><span class="pre">locals()</span></tt></a> functions
returns the current global and local dictionary, respectively, which may be
useful to pass around for use by <a title="eval" class="reference internal" href="#eval"><tt class="xref docutils literal"><span class="pre">eval()</span></tt></a> or <a title="execfile" class="reference internal" href="#execfile"><tt class="xref docutils literal"><span class="pre">execfile()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="execfile">
<tt class="descname">execfile</tt><big>(</big><em>filename</em><span class="optional">[</span>, <em>globals</em><span class="optional">[</span>, <em>locals</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#execfile" title="Permalink to this definition">¶</a></dt>
<dd><p>This function is similar to the <a class="reference external" href="../reference/simple_stmts.html#exec"><tt class="xref docutils literal"><span class="pre">exec</span></tt></a> statement, but parses a file
instead of a string.  It is different from the <a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> statement in
that it does not use the module administration &#8212; it reads the file
unconditionally and does not create a new module. <a class="footnote-reference" href="#id4" id="id1">[1]</a></p>
<p>The arguments are a file name and two optional dictionaries.  The file is parsed
and evaluated as a sequence of Python statements (similarly to a module) using
the <em>globals</em> and <em>locals</em> dictionaries as global and local namespace. If
provided, <em>locals</em> can be any mapping object.</p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>formerly <em>locals</em> was required to be a dictionary.</p>
<p>If the <em>locals</em> dictionary is omitted it defaults to the <em>globals</em> dictionary.
If both dictionaries are omitted, the expression is executed in the environment
where <a title="execfile" class="reference internal" href="#execfile"><tt class="xref docutils literal"><span class="pre">execfile()</span></tt></a> is called.  The return value is <tt class="xref docutils literal"><span class="pre">None</span></tt>.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">The default <em>locals</em> act as described for function <a title="locals" class="reference internal" href="#locals"><tt class="xref docutils literal"><span class="pre">locals()</span></tt></a> below:
modifications to the default <em>locals</em> dictionary should not be attempted.  Pass
an explicit <em>locals</em> dictionary if you need to see effects of the code on
<em>locals</em> after function <a title="execfile" class="reference internal" href="#execfile"><tt class="xref docutils literal"><span class="pre">execfile()</span></tt></a> returns.  <a title="execfile" class="reference internal" href="#execfile"><tt class="xref docutils literal"><span class="pre">execfile()</span></tt></a> cannot be
used reliably to modify a function&#8217;s locals.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="file">
<tt class="descname">file</tt><big>(</big><em>filename</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#file" title="Permalink to this definition">¶</a></dt>
<dd><p>Constructor function for the <a title="file" class="reference internal" href="#file"><tt class="xref docutils literal"><span class="pre">file</span></tt></a> type, described further in section
<a class="reference external" href="stdtypes.html#bltin-file-objects"><em>File Objects</em></a>.  The constructor&#8217;s arguments are the same as those
of the <a title="open" class="reference internal" href="#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> built-in function described below.</p>
<p>When opening a file, it&#8217;s preferable to use <a title="open" class="reference internal" href="#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> instead of  invoking
this constructor directly.  <a title="file" class="reference internal" href="#file"><tt class="xref docutils literal"><span class="pre">file</span></tt></a> is more suited to type testing (for
example, writing <tt class="docutils literal"><span class="pre">isinstance(f,</span> <span class="pre">file)</span></tt>).</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="filter">
<tt class="descname">filter</tt><big>(</big><em>function</em>, <em>iterable</em><big>)</big><a class="headerlink" href="#filter" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a list from those elements of <em>iterable</em> for which <em>function</em> returns
true.  <em>iterable</em> may be either a sequence, a container which supports
iteration, or an iterator.  If <em>iterable</em> is a string or a tuple, the result
also has that type; otherwise it is always a list.  If <em>function</em> is <tt class="xref docutils literal"><span class="pre">None</span></tt>,
the identity function is assumed, that is, all elements of <em>iterable</em> that are
false are removed.</p>
<p>Note that <tt class="docutils literal"><span class="pre">filter(function,</span> <span class="pre">iterable)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">[item</span> <span class="pre">for</span> <span class="pre">item</span> <span class="pre">in</span>
<span class="pre">iterable</span> <span class="pre">if</span> <span class="pre">function(item)]</span></tt> if function is not <tt class="xref docutils literal"><span class="pre">None</span></tt> and <tt class="docutils literal"><span class="pre">[item</span> <span class="pre">for</span> <span class="pre">item</span>
<span class="pre">in</span> <span class="pre">iterable</span> <span class="pre">if</span> <span class="pre">item]</span></tt> if function is <tt class="xref docutils literal"><span class="pre">None</span></tt>.</p>
<p>See <tt class="xref docutils literal"><span class="pre">itertools.filterfalse()</span></tt> for the complementary function that returns
elements of <em>iterable</em> for which <em>function</em> returns false.</p>
</dd></dl>

<dl class="function">
<dt id="float">
<tt class="descname">float</tt><big>(</big><span class="optional">[</span><em>x</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#float" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a string or a number to floating point.  If the argument is a string, it
must contain a possibly signed decimal or floating point number, possibly
embedded in whitespace. The argument may also be [+|-]nan or [+|-]inf.
Otherwise, the argument may be a plain or long integer
or a floating point number, and a floating point number with the same value
(within Python&#8217;s floating point precision) is returned.  If no argument is
given, returns <tt class="docutils literal"><span class="pre">0.0</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last" id="index-328">When passing in a string, values for NaN and Infinity may be returned, depending
on the underlying C library.  Float accepts the strings nan, inf and -inf for
NaN and positive or negative infinity. The case and a leading + are ignored as
well as a leading - is ignored for NaN. Float always represents NaN and infinity
as nan, inf or -inf.</p>
</div>
<p>The float type is described in <a class="reference external" href="stdtypes.html#typesnumeric"><em>Numeric Types &#8212; int, float, long, complex</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="format">
<tt class="descname">format</tt><big>(</big><em>value</em><span class="optional">[</span>, <em>format_spec</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#format" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-329">Convert a <em>value</em> to a &#8220;formatted&#8221; representation, as controlled by
<em>format_spec</em>.  The interpretation of <em>format_spec</em> will depend on the type
of the <em>value</em> argument, however there is a standard formatting syntax that
is used by most built-in types: <a class="reference external" href="string.html#formatspec"><em>Format Specification Mini-Language</em></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><tt class="docutils literal"><span class="pre">format(value,</span> <span class="pre">format_spec)</span></tt> merely calls
<tt class="docutils literal"><span class="pre">value.__format__(format_spec)</span></tt>.</p>
</div>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt>
<tt class="descname">frozenset</tt><big>(</big><span class="optional">[</span><em>iterable</em><span class="optional">]</span><big>)</big></dt>
<dd><p>Return a frozenset object, optionally with elements taken from <em>iterable</em>.
The frozenset type is described in <a class="reference external" href="stdtypes.html#types-set"><em>Set Types &#8212; set, frozenset</em></a>.</p>
<p>For other containers see the built in <a title="dict" class="reference external" href="stdtypes.html#dict"><tt class="xref docutils literal"><span class="pre">dict</span></tt></a>, <a title="list" class="reference internal" href="#list"><tt class="xref docutils literal"><span class="pre">list</span></tt></a>, and
<a title="tuple" class="reference internal" href="#tuple"><tt class="xref docutils literal"><span class="pre">tuple</span></tt></a> classes, and the <a title="High-performance datatypes" class="reference external" href="collections.html#module-collections"><tt class="xref docutils literal"><span class="pre">collections</span></tt></a> module.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

<dl class="function">
<dt id="getattr">
<tt class="descname">getattr</tt><big>(</big><em>object</em>, <em>name</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#getattr" title="Permalink to this definition">¶</a></dt>
<dd>Return the value of the named attributed of <em>object</em>.  <em>name</em> must be a string.
If the string is the name of one of the object&#8217;s attributes, the result is the
value of that attribute.  For example, <tt class="docutils literal"><span class="pre">getattr(x,</span> <span class="pre">'foobar')</span></tt> is equivalent to
<tt class="docutils literal"><span class="pre">x.foobar</span></tt>.  If the named attribute does not exist, <em>default</em> is returned if
provided, otherwise <a title="exceptions.AttributeError" class="reference external" href="exceptions.html#exceptions.AttributeError"><tt class="xref docutils literal"><span class="pre">AttributeError</span></tt></a> is raised.</dd></dl>

<dl class="function">
<dt id="globals">
<tt class="descname">globals</tt><big>(</big><big>)</big><a class="headerlink" href="#globals" title="Permalink to this definition">¶</a></dt>
<dd>Return a dictionary representing the current global symbol table. This is always
the dictionary of the current module (inside a function or method, this is the
module where it is defined, not the module from which it is called).</dd></dl>

<dl class="function">
<dt id="hasattr">
<tt class="descname">hasattr</tt><big>(</big><em>object</em>, <em>name</em><big>)</big><a class="headerlink" href="#hasattr" title="Permalink to this definition">¶</a></dt>
<dd>The arguments are an object and a string.  The result is <tt class="xref docutils literal"><span class="pre">True</span></tt> if the string
is the name of one of the object&#8217;s attributes, <tt class="xref docutils literal"><span class="pre">False</span></tt> if not. (This is
implemented by calling <tt class="docutils literal"><span class="pre">getattr(object,</span> <span class="pre">name)</span></tt> and seeing whether it raises an
exception or not.)</dd></dl>

<dl class="function">
<dt id="hash">
<tt class="descname">hash</tt><big>(</big><em>object</em><big>)</big><a class="headerlink" href="#hash" title="Permalink to this definition">¶</a></dt>
<dd>Return the hash value of the object (if it has one).  Hash values are integers.
They are used to quickly compare dictionary keys during a dictionary lookup.
Numeric values that compare equal have the same hash value (even if they are of
different types, as is the case for 1 and 1.0).</dd></dl>

<dl class="function">
<dt id="help">
<tt class="descname">help</tt><big>(</big><span class="optional">[</span><em>object</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#help" title="Permalink to this definition">¶</a></dt>
<dd><p>Invoke the built-in help system.  (This function is intended for interactive
use.)  If no argument is given, the interactive help system starts on the
interpreter console.  If the argument is a string, then the string is looked up
as the name of a module, function, class, method, keyword, or documentation
topic, and a help page is printed on the console.  If the argument is any other
kind of object, a help page on the object is generated.</p>
<p>This function is added to the built-in namespace by the <a title="A standard way to reference site-specific modules." class="reference external" href="site.html#module-site"><tt class="xref docutils literal"><span class="pre">site</span></tt></a> module.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="hex">
<tt class="descname">hex</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#hex" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert an integer number (of any size) to a hexadecimal string. The result is a
valid Python expression.</p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>Formerly only returned an unsigned literal.</p>
</dd></dl>

<dl class="function">
<dt id="id">
<tt class="descname">id</tt><big>(</big><em>object</em><big>)</big><a class="headerlink" href="#id" title="Permalink to this definition">¶</a></dt>
<dd>Return the &#8220;identity&#8221; of an object.  This is an integer (or long integer) which
is guaranteed to be unique and constant for this object during its lifetime.
Two objects with non-overlapping lifetimes may have the same <a title="id" class="reference internal" href="#id"><tt class="xref docutils literal"><span class="pre">id()</span></tt></a> value.
(Implementation note: this is the address of the object.)</dd></dl>

<dl class="function">
<dt id="input">
<tt class="descname">input</tt><big>(</big><span class="optional">[</span><em>prompt</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#input" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <tt class="docutils literal"><span class="pre">eval(raw_input(prompt))</span></tt>.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">This function is not safe from user errors!  It expects a valid Python
expression as input; if the input is not syntactically valid, a
<a title="exceptions.SyntaxError" class="reference external" href="exceptions.html#exceptions.SyntaxError"><tt class="xref docutils literal"><span class="pre">SyntaxError</span></tt></a> will be raised. Other exceptions may be raised if there is an
error during evaluation.  (On the other hand, sometimes this is exactly what you
need when writing a quick script for expert use.)</p>
</div>
<p>If the <a title="(Unix) GNU readline support for Python." class="reference external" href="readline.html#module-readline"><tt class="xref docutils literal"><span class="pre">readline</span></tt></a> module was loaded, then <a title="input" class="reference internal" href="#input"><tt class="xref docutils literal"><span class="pre">input()</span></tt></a> will use it to
provide elaborate line editing and history features.</p>
<p>Consider using the <a title="raw_input" class="reference internal" href="#raw_input"><tt class="xref docutils literal"><span class="pre">raw_input()</span></tt></a> function for general input from users.</p>
</dd></dl>

<dl class="function">
<dt id="int">
<tt class="descname">int</tt><big>(</big><span class="optional">[</span><em>x</em><span class="optional">[</span>, <em>radix</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#int" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a string or number to a plain integer.  If the argument is a string,
it must contain a possibly signed decimal number representable as a Python
integer, possibly embedded in whitespace.  The <em>radix</em> parameter gives the
base for the conversion (which is 10 by default) and may be any integer in
the range [2, 36], or zero.  If <em>radix</em> is zero, the proper radix is
determined based on the contents of string; the interpretation is the same as
for integer literals.  (See <a class="reference external" href="../reference/lexical_analysis.html#numbers"><em>Numeric literals</em></a>.)  If <em>radix</em> is specified and <em>x</em>
is not a string, <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> is raised. Otherwise, the argument may be a
plain or long integer or a floating point number.  Conversion of floating
point numbers to integers truncates (towards zero).  If the argument is
outside the integer range a long object will be returned instead.  If no
arguments are given, returns <tt class="docutils literal"><span class="pre">0</span></tt>.</p>
<p>The integer type is described in <a class="reference external" href="stdtypes.html#typesnumeric"><em>Numeric Types &#8212; int, float, long, complex</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="isinstance">
<tt class="descname">isinstance</tt><big>(</big><em>object</em>, <em>classinfo</em><big>)</big><a class="headerlink" href="#isinstance" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if the <em>object</em> argument is an instance of the <em>classinfo</em> argument,
or of a (direct or indirect) subclass thereof.  Also return true if <em>classinfo</em>
is a type object (new-style class) and <em>object</em> is an object of that type or of
a (direct or indirect) subclass thereof.  If <em>object</em> is not a class instance or
an object of the given type, the function always returns false.  If <em>classinfo</em>
is neither a class object nor a type object, it may be a tuple of class or type
objects, or may recursively contain other such tuples (other sequence types are
not accepted).  If <em>classinfo</em> is not a class, type, or tuple of classes, types,
and such tuples, a <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> exception is raised.</p>
<p>
<span class="versionmodified">Changed in version 2.2: </span>Support for a tuple of type information was added.</p>
</dd></dl>

<dl class="function">
<dt id="issubclass">
<tt class="descname">issubclass</tt><big>(</big><em>class</em>, <em>classinfo</em><big>)</big><a class="headerlink" href="#issubclass" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if <em>class</em> is a subclass (direct or indirect) of <em>classinfo</em>.  A
class is considered a subclass of itself. <em>classinfo</em> may be a tuple of class
objects, in which case every entry in <em>classinfo</em> will be checked. In any other
case, a <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> exception is raised.</p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>Support for a tuple of type information was added.</p>
</dd></dl>

<dl class="function">
<dt id="iter">
<tt class="descname">iter</tt><big>(</big><em>o</em><span class="optional">[</span>, <em>sentinel</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#iter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an <a class="reference external" href="../glossary.html#term-iterator"><em class="xref">iterator</em></a> object.  The first argument is interpreted very differently
depending on the presence of the second argument. Without a second argument, <em>o</em>
must be a collection object which supports the iteration protocol (the
<a title="object.__iter__" class="reference external" href="../reference/datamodel.html#object.__iter__"><tt class="xref docutils literal"><span class="pre">__iter__()</span></tt></a> method), or it must support the sequence protocol (the
<a title="object.__getitem__" class="reference external" href="../reference/datamodel.html#object.__getitem__"><tt class="xref docutils literal"><span class="pre">__getitem__()</span></tt></a> method with integer arguments starting at <tt class="docutils literal"><span class="pre">0</span></tt>).  If it
does not support either of those protocols, <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> is raised. If the
second argument, <em>sentinel</em>, is given, then <em>o</em> must be a callable object.  The
iterator created in this case will call <em>o</em> with no arguments for each call to
its <a title="next" class="reference internal" href="#next"><tt class="xref docutils literal"><span class="pre">next()</span></tt></a> method; if the value returned is equal to <em>sentinel</em>,
<a title="exceptions.StopIteration" class="reference external" href="exceptions.html#exceptions.StopIteration"><tt class="xref docutils literal"><span class="pre">StopIteration</span></tt></a> will be raised, otherwise the value will be returned.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="len">
<tt class="descname">len</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#len" title="Permalink to this definition">¶</a></dt>
<dd>Return the length (the number of items) of an object.  The argument may be a
sequence (string, tuple or list) or a mapping (dictionary).</dd></dl>

<dl class="function">
<dt id="list">
<tt class="descname">list</tt><big>(</big><span class="optional">[</span><em>iterable</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#list" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list whose items are the same and in the same order as <em>iterable</em>&#8216;s
items.  <em>iterable</em> may be either a sequence, a container that supports
iteration, or an iterator object.  If <em>iterable</em> is already a list, a copy is
made and returned, similar to <tt class="docutils literal"><span class="pre">iterable[:]</span></tt>.  For instance, <tt class="docutils literal"><span class="pre">list('abc')</span></tt>
returns <tt class="docutils literal"><span class="pre">['a',</span> <span class="pre">'b',</span> <span class="pre">'c']</span></tt> and <tt class="docutils literal"><span class="pre">list(</span> <span class="pre">(1,</span> <span class="pre">2,</span> <span class="pre">3)</span> <span class="pre">)</span></tt> returns <tt class="docutils literal"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3]</span></tt>.  If
no argument is given, returns a new empty list, <tt class="docutils literal"><span class="pre">[]</span></tt>.</p>
<p><a title="list" class="reference internal" href="#list"><tt class="xref docutils literal"><span class="pre">list</span></tt></a> is a mutable sequence type, as documented in
<a class="reference external" href="stdtypes.html#typesseq"><em>Sequence Types &#8212; str, unicode, list, tuple, buffer, xrange</em></a>. For other containers see the built in <a title="dict" class="reference external" href="stdtypes.html#dict"><tt class="xref docutils literal"><span class="pre">dict</span></tt></a>,
<a title="set" class="reference external" href="stdtypes.html#set"><tt class="xref docutils literal"><span class="pre">set</span></tt></a>, and <a title="tuple" class="reference internal" href="#tuple"><tt class="xref docutils literal"><span class="pre">tuple</span></tt></a> classes, and the <a title="High-performance datatypes" class="reference external" href="collections.html#module-collections"><tt class="xref docutils literal"><span class="pre">collections</span></tt></a> module.</p>
</dd></dl>

<dl class="function">
<dt id="locals">
<tt class="descname">locals</tt><big>(</big><big>)</big><a class="headerlink" href="#locals" title="Permalink to this definition">¶</a></dt>
<dd><p>Update and return a dictionary representing the current local symbol table.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">The contents of this dictionary should not be modified; changes may not affect
the values of local variables used by the interpreter.</p>
</div>
<p>Free variables are returned by <a title="locals" class="reference internal" href="#locals"><tt class="xref docutils literal"><span class="pre">locals()</span></tt></a> when it is called in a function block.
Modifications of free variables may not affect the values used by the
interpreter.  Free variables are not returned in class blocks.</p>
</dd></dl>

<dl class="function">
<dt id="long">
<tt class="descname">long</tt><big>(</big><span class="optional">[</span><em>x</em><span class="optional">[</span>, <em>radix</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#long" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a string or number to a long integer.  If the argument is a string, it
must contain a possibly signed number of arbitrary size, possibly embedded in
whitespace. The <em>radix</em> argument is interpreted in the same way as for
<a title="int" class="reference internal" href="#int"><tt class="xref docutils literal"><span class="pre">int()</span></tt></a>, and may only be given when <em>x</em> is a string. Otherwise, the argument
may be a plain or long integer or a floating point number, and a long integer
with the same value is returned.    Conversion of floating point numbers to
integers truncates (towards zero).  If no arguments are given, returns <tt class="docutils literal"><span class="pre">0L</span></tt>.</p>
<p>The long type is described in <a class="reference external" href="stdtypes.html#typesnumeric"><em>Numeric Types &#8212; int, float, long, complex</em></a>.</p>
</dd></dl>

<dl class="function">
<dt id="map">
<tt class="descname">map</tt><big>(</big><em>function</em>, <em>iterable</em>, <em>...</em><big>)</big><a class="headerlink" href="#map" title="Permalink to this definition">¶</a></dt>
<dd>Apply <em>function</em> to every item of <em>iterable</em> and return a list of the results.
If additional <em>iterable</em> arguments are passed, <em>function</em> must take that many
arguments and is applied to the items from all iterables in parallel.  If one
iterable is shorter than another it is assumed to be extended with <tt class="xref docutils literal"><span class="pre">None</span></tt>
items.  If <em>function</em> is <tt class="xref docutils literal"><span class="pre">None</span></tt>, the identity function is assumed; if there
are multiple arguments, <a title="map" class="reference internal" href="#map"><tt class="xref docutils literal"><span class="pre">map()</span></tt></a> returns a list consisting of tuples
containing the corresponding items from all iterables (a kind of transpose
operation).  The <em>iterable</em> arguments may be a sequence  or any iterable object;
the result is always a list.</dd></dl>

<dl class="function">
<dt id="max">
<tt class="descname">max</tt><big>(</big><em>iterable</em><span class="optional">[</span>, <em>args...</em><span class="optional">]</span><span class="optional">[</span>, <em>key</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#max" title="Permalink to this definition">¶</a></dt>
<dd><p>With a single argument <em>iterable</em>, return the largest item of a non-empty
iterable (such as a string, tuple or list).  With more than one argument, return
the largest of the arguments.</p>
<p>The optional <em>key</em> argument specifies a one-argument ordering function like that
used for <tt class="xref docutils literal"><span class="pre">list.sort()</span></tt>.  The <em>key</em> argument, if supplied, must be in keyword
form (for example, <tt class="docutils literal"><span class="pre">max(a,b,c,key=func)</span></tt>).</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Added support for the optional <em>key</em> argument.</p>
</dd></dl>

<dl class="function">
<dt id="min">
<tt class="descname">min</tt><big>(</big><em>iterable</em><span class="optional">[</span>, <em>args...</em><span class="optional">]</span><span class="optional">[</span>, <em>key</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#min" title="Permalink to this definition">¶</a></dt>
<dd><p>With a single argument <em>iterable</em>, return the smallest item of a non-empty
iterable (such as a string, tuple or list).  With more than one argument, return
the smallest of the arguments.</p>
<p>The optional <em>key</em> argument specifies a one-argument ordering function like that
used for <tt class="xref docutils literal"><span class="pre">list.sort()</span></tt>.  The <em>key</em> argument, if supplied, must be in keyword
form (for example, <tt class="docutils literal"><span class="pre">min(a,b,c,key=func)</span></tt>).</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Added support for the optional <em>key</em> argument.</p>
</dd></dl>

<dl class="function">
<dt id="next">
<tt class="descname">next</tt><big>(</big><em>iterator</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#next" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the next item from the <em>iterator</em> by calling its <a title="next" class="reference internal" href="#next"><tt class="xref docutils literal"><span class="pre">next()</span></tt></a>
method.  If <em>default</em> is given, it is returned if the iterator is exhausted,
otherwise <a title="exceptions.StopIteration" class="reference external" href="exceptions.html#exceptions.StopIteration"><tt class="xref docutils literal"><span class="pre">StopIteration</span></tt></a> is raised.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="object">
<tt class="descname">object</tt><big>(</big><big>)</big><a class="headerlink" href="#object" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new featureless object.  <a title="object" class="reference internal" href="#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a> is a base for all new style
classes.  It has the methods that are common to all instances of new style
classes.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>This function does not accept any arguments. Formerly, it accepted arguments but
ignored them.</p>
</dd></dl>

<dl class="function">
<dt id="oct">
<tt class="descname">oct</tt><big>(</big><em>x</em><big>)</big><a class="headerlink" href="#oct" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert an integer number (of any size) to an octal string.  The result is a
valid Python expression.</p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>Formerly only returned an unsigned literal.</p>
</dd></dl>

<dl class="function">
<dt id="open">
<tt class="descname">open</tt><big>(</big><em>filename</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#open" title="Permalink to this definition">¶</a></dt>
<dd><p>Open a file, returning an object of the <a title="file" class="reference internal" href="#file"><tt class="xref docutils literal"><span class="pre">file</span></tt></a> type described in
section <a class="reference external" href="stdtypes.html#bltin-file-objects"><em>File Objects</em></a>.  If the file cannot be opened,
<a title="exceptions.IOError" class="reference external" href="exceptions.html#exceptions.IOError"><tt class="xref docutils literal"><span class="pre">IOError</span></tt></a> is raised.  When opening a file, it&#8217;s preferable to use
<a title="open" class="reference internal" href="#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> instead of invoking the <a title="file" class="reference internal" href="#file"><tt class="xref docutils literal"><span class="pre">file</span></tt></a> constructor directly.</p>
<p>The first two arguments are the same as for <tt class="docutils literal"><span class="pre">stdio</span></tt>&#8216;s <tt class="xref docutils literal"><span class="pre">fopen</span></tt>:
<em>filename</em> is the file name to be opened, and <em>mode</em> is a string indicating how
the file is to be opened.</p>
<p>The most commonly-used values of <em>mode</em> are <tt class="docutils literal"><span class="pre">'r'</span></tt> for reading, <tt class="docutils literal"><span class="pre">'w'</span></tt> for
writing (truncating the file if it already exists), and <tt class="docutils literal"><span class="pre">'a'</span></tt> for appending
(which on <em>some</em> Unix systems means that <em>all</em> writes append to the end of the
file regardless of the current seek position).  If <em>mode</em> is omitted, it
defaults to <tt class="docutils literal"><span class="pre">'r'</span></tt>.  The default is to use text mode, which may convert
<tt class="docutils literal"><span class="pre">'\n'</span></tt> characters to a platform-specific representation on writing and back
on reading.  Thus, when opening a binary file, you should append <tt class="docutils literal"><span class="pre">'b'</span></tt> to
the <em>mode</em> value to open the file in binary mode, which will improve
portability.  (Appending <tt class="docutils literal"><span class="pre">'b'</span></tt> is useful even on systems that don&#8217;t treat
binary and text files differently, where it serves as documentation.)  See below
for more possible values of <em>mode</em>.</p>
<p id="index-330">The optional <em>bufsize</em> argument specifies the file&#8217;s desired buffer size: 0
means unbuffered, 1 means line buffered, any other positive value means use a
buffer of (approximately) that size.  A negative <em>bufsize</em> means to use the
system default, which is usually line buffered for tty devices and fully
buffered for other files.  If omitted, the system default is used. <a class="footnote-reference" href="#id5" id="id2">[2]</a></p>
<p>Modes <tt class="docutils literal"><span class="pre">'r+'</span></tt>, <tt class="docutils literal"><span class="pre">'w+'</span></tt> and <tt class="docutils literal"><span class="pre">'a+'</span></tt> open the file for updating (note that
<tt class="docutils literal"><span class="pre">'w+'</span></tt> truncates the file).  Append <tt class="docutils literal"><span class="pre">'b'</span></tt> to the mode to open the file in
binary mode, on systems that differentiate between binary and text files; on
systems that don&#8217;t have this distinction, adding the <tt class="docutils literal"><span class="pre">'b'</span></tt> has no effect.</p>
<p>In addition to the standard <tt class="xref docutils literal"><span class="pre">fopen</span></tt> values <em>mode</em> may be <tt class="docutils literal"><span class="pre">'U'</span></tt> or
<tt class="docutils literal"><span class="pre">'rU'</span></tt>.  Python is usually built with universal newline support; supplying
<tt class="docutils literal"><span class="pre">'U'</span></tt> opens the file as a text file, but lines may be terminated by any of the
following: the Unix end-of-line convention <tt class="docutils literal"><span class="pre">'\n'</span></tt>,  the Macintosh convention
<tt class="docutils literal"><span class="pre">'\r'</span></tt>, or the Windows convention <tt class="docutils literal"><span class="pre">'\r\n'</span></tt>. All of these external
representations are seen as <tt class="docutils literal"><span class="pre">'\n'</span></tt> by the Python program. If Python is built
without universal newline support a <em>mode</em> with <tt class="docutils literal"><span class="pre">'U'</span></tt> is the same as normal
text mode.  Note that file objects so opened also have an attribute called
<tt class="xref docutils literal"><span class="pre">newlines</span></tt> which has a value of <tt class="xref docutils literal"><span class="pre">None</span></tt> (if no newlines have yet been
seen), <tt class="docutils literal"><span class="pre">'\n'</span></tt>, <tt class="docutils literal"><span class="pre">'\r'</span></tt>, <tt class="docutils literal"><span class="pre">'\r\n'</span></tt>, or a tuple containing all the newline
types seen.</p>
<p>Python enforces that the mode, after stripping <tt class="docutils literal"><span class="pre">'U'</span></tt>, begins with <tt class="docutils literal"><span class="pre">'r'</span></tt>,
<tt class="docutils literal"><span class="pre">'w'</span></tt> or <tt class="docutils literal"><span class="pre">'a'</span></tt>.</p>
<p>Python provides many file handling modules including
<a title="Loop over standard input or a list of files." class="reference external" href="fileinput.html#module-fileinput"><tt class="xref docutils literal"><span class="pre">fileinput</span></tt></a>, <a title="Miscellaneous operating system interfaces." class="reference external" href="os.html#module-os"><tt class="xref docutils literal"><span class="pre">os</span></tt></a>, <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>, <a title="Generate temporary files and directories." class="reference external" href="tempfile.html#module-tempfile"><tt class="xref docutils literal"><span class="pre">tempfile</span></tt></a>, and
<a title="High-level file operations, including copying." class="reference external" href="shutil.html#module-shutil"><tt class="xref docutils literal"><span class="pre">shutil</span></tt></a>.</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Restriction on first letter of mode string introduced.</p>
</dd></dl>

<dl class="function">
<dt id="ord">
<tt class="descname">ord</tt><big>(</big><em>c</em><big>)</big><a class="headerlink" href="#ord" title="Permalink to this definition">¶</a></dt>
<dd>Given a string of length one, return an integer representing the Unicode code
point of the character when the argument is a unicode object, or the value of
the byte when the argument is an 8-bit string. For example, <tt class="docutils literal"><span class="pre">ord('a')</span></tt> returns
the integer <tt class="docutils literal"><span class="pre">97</span></tt>, <tt class="docutils literal"><span class="pre">ord(u'\u2020')</span></tt> returns <tt class="docutils literal"><span class="pre">8224</span></tt>.  This is the inverse of
<a title="chr" class="reference internal" href="#chr"><tt class="xref docutils literal"><span class="pre">chr()</span></tt></a> for 8-bit strings and of <a title="unichr" class="reference internal" href="#unichr"><tt class="xref docutils literal"><span class="pre">unichr()</span></tt></a> for unicode objects.  If a
unicode argument is given and Python was built with UCS2 Unicode, then the
character&#8217;s code point must be in the range [0..65535] inclusive; otherwise the
string length is two, and a <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> will be raised.</dd></dl>

<dl class="function">
<dt id="pow">
<tt class="descname">pow</tt><big>(</big><em>x</em>, <em>y</em><span class="optional">[</span>, <em>z</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#pow" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <em>x</em> to the power <em>y</em>; if <em>z</em> is present, return <em>x</em> to the power <em>y</em>,
modulo <em>z</em> (computed more efficiently than <tt class="docutils literal"><span class="pre">pow(x,</span> <span class="pre">y)</span> <span class="pre">%</span> <span class="pre">z</span></tt>). The two-argument
form <tt class="docutils literal"><span class="pre">pow(x,</span> <span class="pre">y)</span></tt> is equivalent to using the power operator: <tt class="docutils literal"><span class="pre">x**y</span></tt>.</p>
<p>The arguments must have numeric types.  With mixed operand types, the coercion
rules for binary arithmetic operators apply.  For int and long int operands, the
result has the same type as the operands (after coercion) unless the second
argument is negative; in that case, all arguments are converted to float and a
float result is delivered.  For example, <tt class="docutils literal"><span class="pre">10**2</span></tt> returns <tt class="docutils literal"><span class="pre">100</span></tt>, but
<tt class="docutils literal"><span class="pre">10**-2</span></tt> returns <tt class="docutils literal"><span class="pre">0.01</span></tt>.  (This last feature was added in Python 2.2.  In
Python 2.1 and before, if both arguments were of integer types and the second
argument was negative, an exception was raised.) If the second argument is
negative, the third argument must be omitted. If <em>z</em> is present, <em>x</em> and <em>y</em>
must be of integer types, and <em>y</em> must be non-negative.  (This restriction was
added in Python 2.2.  In Python 2.1 and before, floating 3-argument <tt class="docutils literal"><span class="pre">pow()</span></tt>
returned platform-dependent results depending on floating-point rounding
accidents.)</p>
</dd></dl>

<dl class="function">
<dt id="print">
<tt class="descname">print</tt><big>(</big><span class="optional">[</span><em>object</em>, <em>...</em><span class="optional">]</span><span class="optional">[</span>, <em>sep=' '</em><span class="optional">]</span><span class="optional">[</span>, <em>end='n'</em><span class="optional">]</span><span class="optional">[</span>, <em>file=sys.stdout</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#print" title="Permalink to this definition">¶</a></dt>
<dd><p>Print <em>object</em>(s) to the stream <em>file</em>, separated by <em>sep</em> and followed by
<em>end</em>.  <em>sep</em>, <em>end</em> and <em>file</em>, if present, must be given as keyword
arguments.</p>
<p>All non-keyword arguments are converted to strings like <a title="str" class="reference internal" href="#str"><tt class="xref docutils literal"><span class="pre">str()</span></tt></a> does and
written to the stream, separated by <em>sep</em> and followed by <em>end</em>.  Both <em>sep</em>
and <em>end</em> must be strings; they can also be <tt class="xref docutils literal"><span class="pre">None</span></tt>, which means to use the
default values.  If no <em>object</em> is given, <a title="print" class="reference internal" href="#print"><tt class="xref docutils literal"><span class="pre">print()</span></tt></a> will just write
<em>end</em>.</p>
<p>The <em>file</em> argument must be an object with a <tt class="docutils literal"><span class="pre">write(string)</span></tt> method; if it
is not present or <tt class="xref docutils literal"><span class="pre">None</span></tt>, <a title="sys.stdout" class="reference external" href="sys.html#sys.stdout"><tt class="xref docutils literal"><span class="pre">sys.stdout</span></tt></a> will be used.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>This function is not normally available as a builtin since the name
<tt class="docutils literal"><span class="pre">print</span></tt> is recognized as the <a class="reference external" href="../reference/simple_stmts.html#print"><tt class="xref docutils literal"><span class="pre">print</span></tt></a> statement.  To disable the
statement and use the <a title="print" class="reference internal" href="#print"><tt class="xref docutils literal"><span class="pre">print()</span></tt></a> function, use this future statement at
the top of your module:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
</pre></div>
</div>
</div>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="property">
<tt class="descname">property</tt><big>(</big><span class="optional">[</span><em>fget</em><span class="optional">[</span>, <em>fset</em><span class="optional">[</span>, <em>fdel</em><span class="optional">[</span>, <em>doc</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#property" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a property attribute for <a class="reference external" href="../glossary.html#term-new-style-class"><em class="xref">new-style class</em></a>es (classes that
derive from <a title="object" class="reference internal" href="#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a>).</p>
<p><em>fget</em> is a function for getting an attribute value, likewise <em>fset</em> is a
function for setting, and <em>fdel</em> a function for del&#8217;ing, an attribute.  Typical
use is to define a managed attribute x:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="k">def</span> <span class="nf">getx</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
    <span class="k">def</span> <span class="nf">setx</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="n">value</span>
    <span class="k">def</span> <span class="nf">delx</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
    <span class="n">x</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">getx</span><span class="p">,</span> <span class="n">setx</span><span class="p">,</span> <span class="n">delx</span><span class="p">,</span> <span class="s">&quot;I&#39;m the &#39;x&#39; property.&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>If given, <em>doc</em> will be the docstring of the property attribute. Otherwise, the
property will copy <em>fget</em>&#8216;s docstring (if it exists).  This makes it possible to
create read-only properties easily using <a title="property" class="reference internal" href="#property"><tt class="xref docutils literal"><span class="pre">property()</span></tt></a> as a <a class="reference external" href="../glossary.html#term-decorator"><em class="xref">decorator</em></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Parrot</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_voltage</span> <span class="o">=</span> <span class="mf">100000</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">voltage</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the current voltage.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_voltage</span>
</pre></div>
</div>
<p>turns the <tt class="xref docutils literal"><span class="pre">voltage()</span></tt> method into a &#8220;getter&#8221; for a read-only attribute
with the same name.</p>
<p>A property object has <tt class="xref docutils literal"><span class="pre">getter</span></tt>, <tt class="xref docutils literal"><span class="pre">setter</span></tt>, and <tt class="xref docutils literal"><span class="pre">deleter</span></tt>
methods usable as decorators that create a copy of the property with the
corresponding accessor function set to the decorated function.  This is
best explained with an example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;I&#39;m the &#39;x&#39; property.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>

    <span class="nd">@x</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_x</span> <span class="o">=</span> <span class="n">value</span>

    <span class="nd">@x</span><span class="o">.</span><span class="n">deleter</span>
    <span class="k">def</span> <span class="nf">x</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_x</span>
</pre></div>
</div>
<p>This code is exactly equivalent to the first example.  Be sure to give the
additional functions the same name as the original property (<tt class="docutils literal"><span class="pre">x</span></tt> in this
case.)</p>
<p>The returned property also has the attributes <tt class="docutils literal"><span class="pre">fget</span></tt>, <tt class="docutils literal"><span class="pre">fset</span></tt>, and
<tt class="docutils literal"><span class="pre">fdel</span></tt> corresponding to the constructor arguments.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Use <em>fget</em>&#8216;s docstring if no <em>doc</em> given.</p>
<p>
<span class="versionmodified">Changed in version 2.6: </span>The <tt class="docutils literal"><span class="pre">getter</span></tt>, <tt class="docutils literal"><span class="pre">setter</span></tt>, and <tt class="docutils literal"><span class="pre">deleter</span></tt> attributes were added.</p>
</dd></dl>

<dl class="function">
<dt id="range">
<tt class="descname">range</tt><big>(</big><span class="optional">[</span><em>start</em><span class="optional">]</span>, <em>stop</em><span class="optional">[</span>, <em>step</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#range" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a versatile function to create lists containing arithmetic progressions.
It is most often used in <a class="reference external" href="../reference/compound_stmts.html#for"><tt class="xref docutils literal"><span class="pre">for</span></tt></a> loops.  The arguments must be plain
integers.  If the <em>step</em> argument is omitted, it defaults to <tt class="docutils literal"><span class="pre">1</span></tt>.  If the
<em>start</em> argument is omitted, it defaults to <tt class="docutils literal"><span class="pre">0</span></tt>.  The full form returns a list
of plain integers <tt class="docutils literal"><span class="pre">[start,</span> <span class="pre">start</span> <span class="pre">+</span> <span class="pre">step,</span> <span class="pre">start</span> <span class="pre">+</span> <span class="pre">2</span> <span class="pre">*</span> <span class="pre">step,</span> <span class="pre">...]</span></tt>.  If <em>step</em>
is positive, the last element is the largest <tt class="docutils literal"><span class="pre">start</span> <span class="pre">+</span> <span class="pre">i</span> <span class="pre">*</span> <span class="pre">step</span></tt> less than
<em>stop</em>; if <em>step</em> is negative, the last element is the smallest <tt class="docutils literal"><span class="pre">start</span> <span class="pre">+</span> <span class="pre">i</span> <span class="pre">*</span>
<span class="pre">step</span></tt> greater than <em>stop</em>.  <em>step</em> must not be zero (or else <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a>
is raised).  Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">10</span><span class="p">)</span>
<span class="go">[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="mf">11</span><span class="p">)</span>
<span class="go">[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span> <span class="mf">30</span><span class="p">,</span> <span class="mf">5</span><span class="p">)</span>
<span class="go">[0, 5, 10, 15, 20, 25]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span> <span class="mf">10</span><span class="p">,</span> <span class="mf">3</span><span class="p">)</span>
<span class="go">[0, 3, 6, 9]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span> <span class="o">-</span><span class="mf">10</span><span class="p">,</span> <span class="o">-</span><span class="mf">1</span><span class="p">)</span>
<span class="go">[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span>
<span class="go">[]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">range</span><span class="p">(</span><span class="mf">1</span><span class="p">,</span> <span class="mf">0</span><span class="p">)</span>
<span class="go">[]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="raw_input">
<tt class="descname">raw_input</tt><big>(</big><span class="optional">[</span><em>prompt</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#raw_input" title="Permalink to this definition">¶</a></dt>
<dd><p>If the <em>prompt</em> argument is present, it is written to standard output without a
trailing newline.  The function then reads a line from input, converts it to a
string (stripping a trailing newline), and returns that. When EOF is read,
<a title="exceptions.EOFError" class="reference external" href="exceptions.html#exceptions.EOFError"><tt class="xref docutils literal"><span class="pre">EOFError</span></tt></a> is raised. Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="nb">raw_input</span><span class="p">(</span><span class="s">&#39;--&gt; &#39;</span><span class="p">)</span>
<span class="go">--&gt; Monty Python&#39;s Flying Circus</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span>
<span class="go">&quot;Monty Python&#39;s Flying Circus&quot;</span>
</pre></div>
</div>
<p>If the <a title="(Unix) GNU readline support for Python." class="reference external" href="readline.html#module-readline"><tt class="xref docutils literal"><span class="pre">readline</span></tt></a> module was loaded, then <a title="raw_input" class="reference internal" href="#raw_input"><tt class="xref docutils literal"><span class="pre">raw_input()</span></tt></a> will use it to
provide elaborate line editing and history features.</p>
</dd></dl>

<dl class="function">
<dt id="reduce">
<tt class="descname">reduce</tt><big>(</big><em>function</em>, <em>iterable</em><span class="optional">[</span>, <em>initializer</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#reduce" title="Permalink to this definition">¶</a></dt>
<dd>Apply <em>function</em> of two arguments cumulatively to the items of <em>iterable</em>, from
left to right, so as to reduce the iterable to a single value.  For example,
<tt class="docutils literal"><span class="pre">reduce(lambda</span> <span class="pre">x,</span> <span class="pre">y:</span> <span class="pre">x+y,</span> <span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4,</span> <span class="pre">5])</span></tt> calculates <tt class="docutils literal"><span class="pre">((((1+2)+3)+4)+5)</span></tt>.
The left argument, <em>x</em>, is the accumulated value and the right argument, <em>y</em>, is
the update value from the <em>iterable</em>.  If the optional <em>initializer</em> is present,
it is placed before the items of the iterable in the calculation, and serves as
a default when the iterable is empty.  If <em>initializer</em> is not given and
<em>iterable</em> contains only one item, the first item is returned.</dd></dl>

<dl class="function">
<dt id="reload">
<tt class="descname">reload</tt><big>(</big><em>module</em><big>)</big><a class="headerlink" href="#reload" title="Permalink to this definition">¶</a></dt>
<dd><p>Reload a previously imported <em>module</em>.  The argument must be a module object, so
it must have been successfully imported before.  This is useful if you have
edited the module source file using an external editor and want to try out the
new version without leaving the Python interpreter.  The return value is the
module object (the same as the <em>module</em> argument).</p>
<p>When <tt class="docutils literal"><span class="pre">reload(module)</span></tt> is executed:</p>
<ul class="simple">
<li>Python modules&#8217; code is recompiled and the module-level code reexecuted,
defining a new set of objects which are bound to names in the module&#8217;s
dictionary.  The <tt class="docutils literal"><span class="pre">init</span></tt> function of extension modules is not called a second
time.</li>
<li>As with all other objects in Python the old objects are only reclaimed after
their reference counts drop to zero.</li>
<li>The names in the module namespace are updated to point to any new or changed
objects.</li>
<li>Other references to the old objects (such as names external to the module) are
not rebound to refer to the new objects and must be updated in each namespace
where they occur if that is desired.</li>
</ul>
<p>There are a number of other caveats:</p>
<p>If a module is syntactically correct but its initialization fails, the first
<a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> statement for it does not bind its name locally, but does
store a (partially initialized) module object in <tt class="docutils literal"><span class="pre">sys.modules</span></tt>.  To reload the
module you must first <a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> it again (this will bind the name to the
partially initialized module object) before you can <a title="reload" class="reference internal" href="#reload"><tt class="xref docutils literal"><span class="pre">reload()</span></tt></a> it.</p>
<p>When a module is reloaded, its dictionary (containing the module&#8217;s global
variables) is retained.  Redefinitions of names will override the old
definitions, so this is generally not a problem.  If the new version of a module
does not define a name that was defined by the old version, the old definition
remains.  This feature can be used to the module&#8217;s advantage if it maintains a
global table or cache of objects &#8212; with a <a class="reference external" href="../reference/compound_stmts.html#try"><tt class="xref docutils literal"><span class="pre">try</span></tt></a> statement it can test
for the table&#8217;s presence and skip its initialization if desired:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span>
    <span class="n">cache</span>
<span class="k">except</span> <span class="ne">NameError</span><span class="p">:</span>
    <span class="n">cache</span> <span class="o">=</span> <span class="p">{}</span>
</pre></div>
</div>
<p>It is legal though generally not very useful to reload built-in or dynamically
loaded modules, except for <a title="Access system-specific parameters and functions." class="reference external" href="sys.html#module-sys"><tt class="xref docutils literal"><span class="pre">sys</span></tt></a>, <a title="The environment where the top-level script is run." class="reference external" href="__main__.html#module-__main__"><tt class="xref docutils literal"><span class="pre">__main__</span></tt></a> and <a title="The module that provides the built-in namespace." class="reference external" href="__builtin__.html#module-__builtin__"><tt class="xref docutils literal"><span class="pre">__builtin__</span></tt></a>.
In many cases, however, extension modules are not designed to be initialized
more than once, and may fail in arbitrary ways when reloaded.</p>
<p>If a module imports objects from another module using <a class="reference external" href="../reference/simple_stmts.html#from"><tt class="xref docutils literal"><span class="pre">from</span></tt></a> ...
<a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> ..., calling <a title="reload" class="reference internal" href="#reload"><tt class="xref docutils literal"><span class="pre">reload()</span></tt></a> for the other module does not
redefine the objects imported from it &#8212; one way around this is to re-execute
the <a class="reference external" href="../reference/simple_stmts.html#from"><tt class="xref docutils literal"><span class="pre">from</span></tt></a> statement, another is to use <a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> and qualified
names (<em>module</em>.*name*) instead.</p>
<p>If a module instantiates instances of a class, reloading the module that defines
the class does not affect the method definitions of the instances &#8212; they
continue to use the old class definition.  The same is true for derived classes.</p>
</dd></dl>

<dl class="function">
<dt id="repr">
<tt class="descname">repr</tt><big>(</big><em>object</em><big>)</big><a class="headerlink" href="#repr" title="Permalink to this definition">¶</a></dt>
<dd>Return a string containing a printable representation of an object.  This is
the same value yielded by conversions (reverse quotes).  It is sometimes
useful to be able to access this operation as an ordinary function.  For many
types, this function makes an attempt to return a string that would yield an
object with the same value when passed to <a title="eval" class="reference internal" href="#eval"><tt class="xref docutils literal"><span class="pre">eval()</span></tt></a>, otherwise the
representation is a string enclosed in angle brackets that contains the name
of the type of the object together with additional information often
including the name and address of the object.  A class can control what this
function returns for its instances by defining a <a title="object.__repr__" class="reference external" href="../reference/datamodel.html#object.__repr__"><tt class="xref docutils literal"><span class="pre">__repr__()</span></tt></a> method.</dd></dl>

<dl class="function">
<dt id="reversed">
<tt class="descname">reversed</tt><big>(</big><em>seq</em><big>)</big><a class="headerlink" href="#reversed" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a reverse <a class="reference external" href="../glossary.html#term-iterator"><em class="xref">iterator</em></a>.  <em>seq</em> must be an object which has
a <a title="object.__reversed__" class="reference external" href="../reference/datamodel.html#object.__reversed__"><tt class="xref docutils literal"><span class="pre">__reversed__()</span></tt></a> method or supports the sequence protocol (the
<a title="object.__len__" class="reference external" href="../reference/datamodel.html#object.__len__"><tt class="xref docutils literal"><span class="pre">__len__()</span></tt></a> method and the <a title="object.__getitem__" class="reference external" href="../reference/datamodel.html#object.__getitem__"><tt class="xref docutils literal"><span class="pre">__getitem__()</span></tt></a> method with integer
arguments starting at <tt class="docutils literal"><span class="pre">0</span></tt>).</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
<p>
<span class="versionmodified">Changed in version 2.6: </span>Added the possibility to write a custom <a title="object.__reversed__" class="reference external" href="../reference/datamodel.html#object.__reversed__"><tt class="xref docutils literal"><span class="pre">__reversed__()</span></tt></a> method.</p>
</dd></dl>

<dl class="function">
<dt id="round">
<tt class="descname">round</tt><big>(</big><em>x</em><span class="optional">[</span>, <em>n</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#round" title="Permalink to this definition">¶</a></dt>
<dd>Return the floating point value <em>x</em> rounded to <em>n</em> digits after the decimal
point.  If <em>n</em> is omitted, it defaults to zero. The result is a floating point
number.  Values are rounded to the closest multiple of 10 to the power minus
<em>n</em>; if two multiples are equally close, rounding is done away from 0 (so. for
example, <tt class="docutils literal"><span class="pre">round(0.5)</span></tt> is <tt class="docutils literal"><span class="pre">1.0</span></tt> and <tt class="docutils literal"><span class="pre">round(-0.5)</span></tt> is <tt class="docutils literal"><span class="pre">-1.0</span></tt>).</dd></dl>

<dl class="function">
<dt>
<tt class="descname">set</tt><big>(</big><span class="optional">[</span><em>iterable</em><span class="optional">]</span><big>)</big></dt>
<dd><p>Return a new set, optionally with elements are taken from <em>iterable</em>.
The set type is described in <a class="reference external" href="stdtypes.html#types-set"><em>Set Types &#8212; set, frozenset</em></a>.</p>
<p>For other containers see the built in <a title="dict" class="reference external" href="stdtypes.html#dict"><tt class="xref docutils literal"><span class="pre">dict</span></tt></a>, <a title="list" class="reference internal" href="#list"><tt class="xref docutils literal"><span class="pre">list</span></tt></a>, and
<a title="tuple" class="reference internal" href="#tuple"><tt class="xref docutils literal"><span class="pre">tuple</span></tt></a> classes, and the <a title="High-performance datatypes" class="reference external" href="collections.html#module-collections"><tt class="xref docutils literal"><span class="pre">collections</span></tt></a> module.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

<dl class="function">
<dt id="setattr">
<tt class="descname">setattr</tt><big>(</big><em>object</em>, <em>name</em>, <em>value</em><big>)</big><a class="headerlink" href="#setattr" title="Permalink to this definition">¶</a></dt>
<dd>This is the counterpart of <a title="getattr" class="reference internal" href="#getattr"><tt class="xref docutils literal"><span class="pre">getattr()</span></tt></a>.  The arguments are an object, a
string and an arbitrary value.  The string may name an existing attribute or a
new attribute.  The function assigns the value to the attribute, provided the
object allows it.  For example, <tt class="docutils literal"><span class="pre">setattr(x,</span> <span class="pre">'foobar',</span> <span class="pre">123)</span></tt> is equivalent to
<tt class="docutils literal"><span class="pre">x.foobar</span> <span class="pre">=</span> <span class="pre">123</span></tt>.</dd></dl>

<dl class="function">
<dt id="slice">
<tt class="descname">slice</tt><big>(</big><span class="optional">[</span><em>start</em><span class="optional">]</span>, <em>stop</em><span class="optional">[</span>, <em>step</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#slice" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-331">Return a <a class="reference external" href="../glossary.html#term-slice"><em class="xref">slice</em></a> object representing the set of indices specified by
<tt class="docutils literal"><span class="pre">range(start,</span> <span class="pre">stop,</span> <span class="pre">step)</span></tt>.  The <em>start</em> and <em>step</em> arguments default to
<tt class="xref docutils literal"><span class="pre">None</span></tt>.  Slice objects have read-only data attributes <tt class="xref docutils literal"><span class="pre">start</span></tt>,
<tt class="xref docutils literal"><span class="pre">stop</span></tt> and <tt class="xref docutils literal"><span class="pre">step</span></tt> which merely return the argument values (or their
default).  They have no other explicit functionality; however they are used by
Numerical Python and other third party extensions.  Slice objects are also
generated when extended indexing syntax is used.  For example:
<tt class="docutils literal"><span class="pre">a[start:stop:step]</span></tt> or <tt class="docutils literal"><span class="pre">a[start:stop,</span> <span class="pre">i]</span></tt>.  See <a title="itertools.islice" class="reference external" href="itertools.html#itertools.islice"><tt class="xref docutils literal"><span class="pre">itertools.islice()</span></tt></a>
for an alternate version that returns an iterator.</p>
</dd></dl>

<dl class="function">
<dt id="sorted">
<tt class="descname">sorted</tt><big>(</big><em>iterable</em><span class="optional">[</span>, <em>cmp</em><span class="optional">[</span>, <em>key</em><span class="optional">[</span>, <em>reverse</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#sorted" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new sorted list from the items in <em>iterable</em>.</p>
<p>The optional arguments <em>cmp</em>, <em>key</em>, and <em>reverse</em> have the same meaning as
those for the <tt class="xref docutils literal"><span class="pre">list.sort()</span></tt> method (described in section
<a class="reference external" href="stdtypes.html#typesseq-mutable"><em>Mutable Sequence Types</em></a>).</p>
<p><em>cmp</em> specifies a custom comparison function of two arguments (iterable
elements) which should return a negative, zero or positive number depending on
whether the first argument is considered smaller than, equal to, or larger than
the second argument: <tt class="docutils literal"><span class="pre">cmp=lambda</span> <span class="pre">x,y:</span> <span class="pre">cmp(x.lower(),</span> <span class="pre">y.lower())</span></tt>.  The default
value is <tt class="xref docutils literal"><span class="pre">None</span></tt>.</p>
<p><em>key</em> specifies a function of one argument that is used to extract a comparison
key from each list element: <tt class="docutils literal"><span class="pre">key=str.lower</span></tt>.  The default value is <tt class="xref docutils literal"><span class="pre">None</span></tt>.</p>
<p><em>reverse</em> is a boolean value.  If set to <tt class="xref docutils literal"><span class="pre">True</span></tt>, then the list elements are
sorted as if each comparison were reversed.</p>
<p>In general, the <em>key</em> and <em>reverse</em> conversion processes are much faster
than specifying an equivalent <em>cmp</em> function.  This is because <em>cmp</em> is
called multiple times for each list element while <em>key</em> and <em>reverse</em> touch
each element only once.  To convert an old-style <em>cmp</em> function to a <em>key</em>
function, see the <a class="reference external" href="http://code.activestate.com/recipes/576653/">CmpToKey recipe in the ASPN cookbook</a>.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

<dl class="function">
<dt id="staticmethod">
<tt class="descname">staticmethod</tt><big>(</big><em>function</em><big>)</big><a class="headerlink" href="#staticmethod" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a static method for <em>function</em>.</p>
<p>A static method does not receive an implicit first argument. To declare a static
method, use this idiom:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="o">...</span><span class="p">):</span> <span class="o">...</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">&#64;staticmethod</span></tt> form is a function <a class="reference external" href="../glossary.html#term-decorator"><em class="xref">decorator</em></a> &#8211; see the
description of function definitions in <a class="reference external" href="../reference/compound_stmts.html#function"><em>Function definitions</em></a> for details.</p>
<p>It can be called either on the class (such as <tt class="docutils literal"><span class="pre">C.f()</span></tt>) or on an instance (such
as <tt class="docutils literal"><span class="pre">C().f()</span></tt>).  The instance is ignored except for its class.</p>
<p>Static methods in Python are similar to those found in Java or C++. For a more
advanced concept, see <a title="classmethod" class="reference internal" href="#classmethod"><tt class="xref docutils literal"><span class="pre">classmethod()</span></tt></a> in this section.</p>
<p>For more information on static methods, consult the documentation on the
standard type hierarchy in <a class="reference external" href="../reference/datamodel.html#types"><em>The standard type hierarchy</em></a>.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>Function decorator syntax added.</p>
</dd></dl>

<dl class="function">
<dt id="str">
<tt class="descname">str</tt><big>(</big><span class="optional">[</span><em>object</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#str" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string containing a nicely printable representation of an object.  For
strings, this returns the string itself.  The difference with <tt class="docutils literal"><span class="pre">repr(object)</span></tt>
is that <tt class="docutils literal"><span class="pre">str(object)</span></tt> does not always attempt to return a string that is
acceptable to <a title="eval" class="reference internal" href="#eval"><tt class="xref docutils literal"><span class="pre">eval()</span></tt></a>; its goal is to return a printable string.  If no
argument is given, returns the empty string, <tt class="docutils literal"><span class="pre">''</span></tt>.</p>
<p>For more information on strings see <a class="reference external" href="stdtypes.html#typesseq"><em>Sequence Types &#8212; str, unicode, list, tuple, buffer, xrange</em></a> which describes sequence
functionality (strings are sequences), and also the string-specific methods
described in the <a class="reference external" href="stdtypes.html#string-methods"><em>String Methods</em></a> section. To output formatted strings
use template strings or the <tt class="docutils literal"><span class="pre">%</span></tt> operator described in the
<a class="reference external" href="stdtypes.html#string-formatting"><em>String Formatting Operations</em></a> section. In addition see the <a class="reference external" href="strings.html#stringservices"><em>String Services</em></a>
section. See also <a title="unicode" class="reference internal" href="#unicode"><tt class="xref docutils literal"><span class="pre">unicode()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="sum">
<tt class="descname">sum</tt><big>(</big><em>iterable</em><span class="optional">[</span>, <em>start</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#sum" title="Permalink to this definition">¶</a></dt>
<dd><p>Sums <em>start</em> and the items of an <em>iterable</em> from left to right and returns the
total.  <em>start</em> defaults to <tt class="docutils literal"><span class="pre">0</span></tt>. The <em>iterable</em>&#8216;s items are normally numbers,
and are not allowed to be strings.  The fast, correct way to concatenate a
sequence of strings is by calling <tt class="docutils literal"><span class="pre">''.join(sequence)</span></tt>. Note that
<tt class="docutils literal"><span class="pre">sum(range(n),</span> <span class="pre">m)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">reduce(operator.add,</span> <span class="pre">range(n),</span> <span class="pre">m)</span></tt>
To add floating point values with extended precision, see <a title="math.fsum" class="reference external" href="math.html#math.fsum"><tt class="xref docutils literal"><span class="pre">math.fsum()</span></tt></a>.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="super">
<tt class="descname">super</tt><big>(</big><em>type</em><span class="optional">[</span>, <em>object-or-type</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#super" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a proxy object that delegates method calls to a parent or sibling
class of <em>type</em>.  This is useful for accessing inherited methods that have
been overridden in a class. The search order is same as that used by
<a title="getattr" class="reference internal" href="#getattr"><tt class="xref docutils literal"><span class="pre">getattr()</span></tt></a> except that the <em>type</em> itself is skipped.</p>
<p>The <tt class="xref docutils literal"><span class="pre">__mro__</span></tt> attribute of the <em>type</em> lists the method resolution
search order used by both <a title="getattr" class="reference internal" href="#getattr"><tt class="xref docutils literal"><span class="pre">getattr()</span></tt></a> and <a title="super" class="reference internal" href="#super"><tt class="xref docutils literal"><span class="pre">super()</span></tt></a>.  The attribute
is dynamic and can change whenever the inheritance hierarchy is updated.</p>
<p>If the second argument is omitted, the super object returned is unbound.  If
the second argument is an object, <tt class="docutils literal"><span class="pre">isinstance(obj,</span> <span class="pre">type)</span></tt> must be true.  If
the second argument is a type, <tt class="docutils literal"><span class="pre">issubclass(type2,</span> <span class="pre">type)</span></tt> must be true (this
is useful for classmethods).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a title="super" class="reference internal" href="#super"><tt class="xref docutils literal"><span class="pre">super()</span></tt></a> only works for <a class="reference external" href="../glossary.html#term-new-style-class"><em class="xref">new-style class</em></a>es.</p>
</div>
<p>There are two typical use cases for <em>super</em>.  In a class hierarchy with
single inheritance, <em>super</em> can be used to refer to parent classes without
naming them explicitly, thus making the code more maintainable.  This use
closely parallels the use of <em>super</em> in other programming languages.</p>
<p>The second use case is to support cooperative multiple inheritance in a
dynamic execution environment.  This use case is unique to Python and is
not found in statically compiled languages or languages that only support
single inheritance.  This makes it possible to implement &#8220;diamond diagrams&#8221;
where multiple base classes implement the same method.  Good design dictates
that this method have the same calling signature in every case (because the
order of calls is determined at runtime, because that order adapts
to changes in the class hierarchy, and because that order can include
sibling classes that are unknown prior to runtime).</p>
<p>For both use cases, a typical superclass call looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="n">B</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">method</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">arg</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">method</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that <a title="super" class="reference internal" href="#super"><tt class="xref docutils literal"><span class="pre">super()</span></tt></a> is implemented as part of the binding process for
explicit dotted attribute lookups such as <tt class="docutils literal"><span class="pre">super().__getitem__(name)</span></tt>.
It does so by implementing its own <a title="object.__getattribute__" class="reference external" href="../reference/datamodel.html#object.__getattribute__"><tt class="xref docutils literal"><span class="pre">__getattribute__()</span></tt></a> method for searching
classes in a predictable order that supports cooperative multiple inheritance.
Accordingly, <a title="super" class="reference internal" href="#super"><tt class="xref docutils literal"><span class="pre">super()</span></tt></a> is undefined for implicit lookups using statements or
operators such as <tt class="docutils literal"><span class="pre">super()[name]</span></tt>.</p>
<p>Also note that <a title="super" class="reference internal" href="#super"><tt class="xref docutils literal"><span class="pre">super()</span></tt></a> is not limited to use inside methods.  The two
argument form specifies the arguments exactly and makes the appropriate
references.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="tuple">
<tt class="descname">tuple</tt><big>(</big><span class="optional">[</span><em>iterable</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#tuple" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple whose items are the same and in the same order as <em>iterable</em>&#8216;s
items.  <em>iterable</em> may be a sequence, a container that supports iteration, or an
iterator object. If <em>iterable</em> is already a tuple, it is returned unchanged.
For instance, <tt class="docutils literal"><span class="pre">tuple('abc')</span></tt> returns <tt class="docutils literal"><span class="pre">('a',</span> <span class="pre">'b',</span> <span class="pre">'c')</span></tt> and <tt class="docutils literal"><span class="pre">tuple([1,</span> <span class="pre">2,</span>
<span class="pre">3])</span></tt> returns <tt class="docutils literal"><span class="pre">(1,</span> <span class="pre">2,</span> <span class="pre">3)</span></tt>.  If no argument is given, returns a new empty
tuple, <tt class="docutils literal"><span class="pre">()</span></tt>.</p>
<p><a title="tuple" class="reference internal" href="#tuple"><tt class="xref docutils literal"><span class="pre">tuple</span></tt></a> is an immutable sequence type, as documented in
<a class="reference external" href="stdtypes.html#typesseq"><em>Sequence Types &#8212; str, unicode, list, tuple, buffer, xrange</em></a>. For other containers see the built in <a title="dict" class="reference external" href="stdtypes.html#dict"><tt class="xref docutils literal"><span class="pre">dict</span></tt></a>,
<a title="list" class="reference internal" href="#list"><tt class="xref docutils literal"><span class="pre">list</span></tt></a>, and <a title="set" class="reference external" href="stdtypes.html#set"><tt class="xref docutils literal"><span class="pre">set</span></tt></a> classes, and the <a title="High-performance datatypes" class="reference external" href="collections.html#module-collections"><tt class="xref docutils literal"><span class="pre">collections</span></tt></a> module.</p>
</dd></dl>

<dl class="function">
<dt id="type">
<tt class="descname">type</tt><big>(</big><em>object</em><big>)</big><a class="headerlink" href="#type" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-332">Return the type of an <em>object</em>.  The return value is a type object.  The
<a title="isinstance" class="reference internal" href="#isinstance"><tt class="xref docutils literal"><span class="pre">isinstance()</span></tt></a> built-in function is recommended for testing the type of an
object.</p>
<p>With three arguments, <a title="type" class="reference internal" href="#type"><tt class="xref docutils literal"><span class="pre">type()</span></tt></a> functions as a constructor as detailed below.</p>
</dd></dl>

<dl class="function">
<dt>
<tt class="descname">type</tt><big>(</big><em>name</em>, <em>bases</em>, <em>dict</em><big>)</big></dt>
<dd><p>Return a new type object.  This is essentially a dynamic form of the
<a class="reference external" href="../reference/compound_stmts.html#class"><tt class="xref docutils literal"><span class="pre">class</span></tt></a> statement. The <em>name</em> string is the class name and becomes the
<tt class="xref docutils literal"><span class="pre">__name__</span></tt> attribute; the <em>bases</em> tuple itemizes the base classes and
becomes the <tt class="xref docutils literal"><span class="pre">__bases__</span></tt> attribute; and the <em>dict</em> dictionary is the
namespace containing definitions for class body and becomes the <tt class="xref docutils literal"><span class="pre">__dict__</span></tt>
attribute.  For example, the following two statements create identical
<a title="type" class="reference internal" href="#type"><tt class="xref docutils literal"><span class="pre">type</span></tt></a> objects:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">X</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">a</span> <span class="o">=</span> <span class="mf">1</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span> <span class="o">=</span> <span class="nb">type</span><span class="p">(</span><span class="s">&#39;X&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nb">object</span><span class="p">,),</span> <span class="nb">dict</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="mf">1</span><span class="p">))</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="unichr">
<tt class="descname">unichr</tt><big>(</big><em>i</em><big>)</big><a class="headerlink" href="#unichr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the Unicode string of one character whose Unicode code is the integer
<em>i</em>.  For example, <tt class="docutils literal"><span class="pre">unichr(97)</span></tt> returns the string <tt class="docutils literal"><span class="pre">u'a'</span></tt>.  This is the
inverse of <a title="ord" class="reference internal" href="#ord"><tt class="xref docutils literal"><span class="pre">ord()</span></tt></a> for Unicode strings.  The valid range for the argument
depends how Python was configured &#8211; it may be either UCS2 [0..0xFFFF] or UCS4
[0..0x10FFFF]. <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised otherwise. For ASCII and 8-bit
strings see <a title="chr" class="reference internal" href="#chr"><tt class="xref docutils literal"><span class="pre">chr()</span></tt></a>.</p>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
</dd></dl>

<dl class="function">
<dt id="unicode">
<tt class="descname">unicode</tt><big>(</big><span class="optional">[</span><em>object</em><span class="optional">[</span>, <em>encoding</em><span class="optional">[</span>, <em>errors</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#unicode" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the Unicode string version of <em>object</em> using one of the following modes:</p>
<p>If <em>encoding</em> and/or <em>errors</em> are given, <tt class="docutils literal"><span class="pre">unicode()</span></tt> will decode the object
which can either be an 8-bit string or a character buffer using the codec for
<em>encoding</em>. The <em>encoding</em> parameter is a string giving the name of an encoding;
if the encoding is not known, <a title="exceptions.LookupError" class="reference external" href="exceptions.html#exceptions.LookupError"><tt class="xref docutils literal"><span class="pre">LookupError</span></tt></a> is raised. Error handling is
done according to <em>errors</em>; this specifies the treatment of characters which are
invalid in the input encoding.  If <em>errors</em> is <tt class="docutils literal"><span class="pre">'strict'</span></tt> (the default), a
<a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised on errors, while a value of <tt class="docutils literal"><span class="pre">'ignore'</span></tt> causes
errors to be silently ignored, and a value of <tt class="docutils literal"><span class="pre">'replace'</span></tt> causes the official
Unicode replacement character, <tt class="docutils literal"><span class="pre">U+FFFD</span></tt>, to be used to replace input
characters which cannot be decoded.  See also the <a title="Encode and decode data and streams." class="reference external" href="codecs.html#module-codecs"><tt class="xref docutils literal"><span class="pre">codecs</span></tt></a> module.</p>
<p>If no optional parameters are given, <tt class="docutils literal"><span class="pre">unicode()</span></tt> will mimic the behaviour of
<tt class="docutils literal"><span class="pre">str()</span></tt> except that it returns Unicode strings instead of 8-bit strings. More
precisely, if <em>object</em> is a Unicode string or subclass it will return that
Unicode string without any additional decoding applied.</p>
<p>For objects which provide a <a title="object.__unicode__" class="reference external" href="../reference/datamodel.html#object.__unicode__"><tt class="xref docutils literal"><span class="pre">__unicode__()</span></tt></a> method, it will call this method
without arguments to create a Unicode string. For all other objects, the 8-bit
string version or representation is requested and then converted to a Unicode
string using the codec for the default encoding in <tt class="docutils literal"><span class="pre">'strict'</span></tt> mode.</p>
<p>For more information on Unicode strings see <a class="reference external" href="stdtypes.html#typesseq"><em>Sequence Types &#8212; str, unicode, list, tuple, buffer, xrange</em></a> which describes
sequence functionality (Unicode strings are sequences), and also the
string-specific methods described in the <a class="reference external" href="stdtypes.html#string-methods"><em>String Methods</em></a> section. To
output formatted strings use template strings or the <tt class="docutils literal"><span class="pre">%</span></tt> operator described
in the <a class="reference external" href="stdtypes.html#string-formatting"><em>String Formatting Operations</em></a> section. In addition see the
<a class="reference external" href="strings.html#stringservices"><em>String Services</em></a> section. See also <a title="str" class="reference internal" href="#str"><tt class="xref docutils literal"><span class="pre">str()</span></tt></a>.</p>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
<p>
<span class="versionmodified">Changed in version 2.2: </span>Support for <a title="object.__unicode__" class="reference external" href="../reference/datamodel.html#object.__unicode__"><tt class="xref docutils literal"><span class="pre">__unicode__()</span></tt></a> added.</p>
</dd></dl>

<dl class="function">
<dt id="vars">
<tt class="descname">vars</tt><big>(</big><span class="optional">[</span><em>object</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#vars" title="Permalink to this definition">¶</a></dt>
<dd><p>Without arguments, return a dictionary corresponding to the current local symbol
table.  With a module, class or class instance object as argument (or anything
else that has a <tt class="xref docutils literal"><span class="pre">__dict__</span></tt> attribute), returns a dictionary corresponding
to the object&#8217;s symbol table.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">The returned dictionary should not be modified:
the effects on the corresponding symbol table are undefined. <a class="footnote-reference" href="#id6" id="id3">[3]</a></p>
</div>
</dd></dl>

<dl class="function">
<dt id="xrange">
<tt class="descname">xrange</tt><big>(</big><span class="optional">[</span><em>start</em><span class="optional">]</span>, <em>stop</em><span class="optional">[</span>, <em>step</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#xrange" title="Permalink to this definition">¶</a></dt>
<dd><p>This function is very similar to <a title="range" class="reference internal" href="#range"><tt class="xref docutils literal"><span class="pre">range()</span></tt></a>, but returns an &#8220;xrange object&#8221;
instead of a list.  This is an opaque sequence type which yields the same values
as the corresponding list, without actually storing them all simultaneously.
The advantage of <a title="xrange" class="reference internal" href="#xrange"><tt class="xref docutils literal"><span class="pre">xrange()</span></tt></a> over <a title="range" class="reference internal" href="#range"><tt class="xref docutils literal"><span class="pre">range()</span></tt></a> is minimal (since
<a title="xrange" class="reference internal" href="#xrange"><tt class="xref docutils literal"><span class="pre">xrange()</span></tt></a> still has to create the values when asked for them) except when a
very large range is used on a memory-starved machine or when all of the range&#8217;s
elements are never used (such as when the loop is usually terminated with
<a class="reference external" href="../reference/simple_stmts.html#break"><tt class="xref docutils literal"><span class="pre">break</span></tt></a>).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a title="xrange" class="reference internal" href="#xrange"><tt class="xref docutils literal"><span class="pre">xrange()</span></tt></a> is intended to be simple and fast. Implementations may impose
restrictions to achieve this. The C implementation of Python restricts all
arguments to native C longs (&#8220;short&#8221; Python integers), and also requires that
the number of elements fit in a native C long.  If a larger range is needed,
an alternate version can be crafted using the <a title="Functions creating iterators for efficient looping." class="reference external" href="itertools.html#module-itertools"><tt class="xref docutils literal"><span class="pre">itertools</span></tt></a> module:
<tt class="docutils literal"><span class="pre">islice(count(start,</span> <span class="pre">step),</span> <span class="pre">(stop-start+step-1)//step)</span></tt>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="zip">
<tt class="descname">zip</tt><big>(</big><span class="optional">[</span><em>iterable</em>, <em>...</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#zip" title="Permalink to this definition">¶</a></dt>
<dd><p>This function returns a list of tuples, where the <em>i</em>-th tuple contains the
<em>i</em>-th element from each of the argument sequences or iterables. The returned
list is truncated in length to the length of the shortest argument sequence.
When there are multiple arguments which are all of the same length, <a title="zip" class="reference internal" href="#zip"><tt class="xref docutils literal"><span class="pre">zip()</span></tt></a>
is similar to <a title="map" class="reference internal" href="#map"><tt class="xref docutils literal"><span class="pre">map()</span></tt></a> with an initial argument of <tt class="xref docutils literal"><span class="pre">None</span></tt>. With a single
sequence argument, it returns a list of 1-tuples. With no arguments, it returns
an empty list.</p>
<p>The left-to-right evaluation order of the iterables is guaranteed. This
makes possible an idiom for clustering a data series into n-length groups
using <tt class="docutils literal"><span class="pre">zip(*[iter(s)]*n)</span></tt>.</p>
<p><a title="zip" class="reference internal" href="#zip"><tt class="xref docutils literal"><span class="pre">zip()</span></tt></a> in conjunction with the <tt class="docutils literal"><span class="pre">*</span></tt> operator can be used to unzip a
list:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1</span><span class="p">,</span> <span class="mf">2</span><span class="p">,</span> <span class="mf">3</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mf">4</span><span class="p">,</span> <span class="mf">5</span><span class="p">,</span> <span class="mf">6</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zipped</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zipped</span>
<span class="go">[(1, 4), (2, 5), (3, 6)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x2</span><span class="p">,</span> <span class="n">y2</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">zipped</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">==</span> <span class="n">x2</span><span class="p">,</span> <span class="n">y</span> <span class="o">==</span> <span class="n">y2</span>
<span class="go">True</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
<p>
<span class="versionmodified">Changed in version 2.4: </span>Formerly, <a title="zip" class="reference internal" href="#zip"><tt class="xref docutils literal"><span class="pre">zip()</span></tt></a> required at least one argument and <tt class="docutils literal"><span class="pre">zip()</span></tt> raised a
<a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a> instead of returning an empty list.</p>
</dd></dl>

<dl class="function">
<dt id="__import__">
<tt class="descname">__import__</tt><big>(</big><em>name</em><span class="optional">[</span>, <em>globals</em><span class="optional">[</span>, <em>locals</em><span class="optional">[</span>, <em>fromlist</em><span class="optional">[</span>, <em>level</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#__import__" title="Permalink to this definition">¶</a></dt>
<dd><div class="admonition note" id="index-333">
<p class="first admonition-title">Note</p>
<p class="last">This is an advanced function that is not needed in everyday Python
programming.</p>
</div>
<p>This function is invoked by the <a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> statement.  It can be
replaced (by importing the <tt class="xref docutils literal"><span class="pre">builtins</span></tt> module and assigning to
<tt class="docutils literal"><span class="pre">builtins.__import__</span></tt>) in order to change semantics of the
<a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> statement, but nowadays it is usually simpler to use import
hooks (see <span class="target" id="index-334"></span><a class="reference external" href="http://www.python.org/dev/peps/pep-0302"><strong>PEP 302</strong></a>).  Direct use of <a title="__import__" class="reference internal" href="#__import__"><tt class="xref docutils literal"><span class="pre">__import__()</span></tt></a> is rare, except in
cases where you want to import a module whose name is only known at runtime.</p>
<p>The function imports the module <em>name</em>, potentially using the given <em>globals</em>
and <em>locals</em> to determine how to interpret the name in a package context.
The <em>fromlist</em> gives the names of objects or submodules that should be
imported from the module given by <em>name</em>.  The standard implementation does
not use its <em>locals</em> argument at all, and uses its <em>globals</em> only to
determine the package context of the <a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> statement.</p>
<p><em>level</em> specifies whether to use absolute or relative imports.  The default
is <tt class="docutils literal"><span class="pre">-1</span></tt> which indicates both absolute and relative imports will be
attempted.  <tt class="docutils literal"><span class="pre">0</span></tt> means only perform absolute imports.  Positive values for
<em>level</em> indicate the number of parent directories to search relative to the
directory of the module calling <a title="__import__" class="reference internal" href="#__import__"><tt class="xref docutils literal"><span class="pre">__import__()</span></tt></a>.</p>
<p>When the <em>name</em> variable is of the form <tt class="docutils literal"><span class="pre">package.module</span></tt>, normally, the
top-level package (the name up till the first dot) is returned, <em>not</em> the
module named by <em>name</em>.  However, when a non-empty <em>fromlist</em> argument is
given, the module named by <em>name</em> is returned.</p>
<p>For example, the statement <tt class="docutils literal"><span class="pre">import</span> <span class="pre">spam</span></tt> results in bytecode resembling the
following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">spam</span> <span class="o">=</span> <span class="nb">__import__</span><span class="p">(</span><span class="s">&#39;spam&#39;</span><span class="p">,</span> <span class="nb">globals</span><span class="p">(),</span> <span class="nb">locals</span><span class="p">(),</span> <span class="p">[],</span> <span class="o">-</span><span class="mf">1</span><span class="p">)</span>
</pre></div>
</div>
<p>The statement <tt class="docutils literal"><span class="pre">import</span> <span class="pre">spam.ham</span></tt> results in this call:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">spam</span> <span class="o">=</span> <span class="nb">__import__</span><span class="p">(</span><span class="s">&#39;spam.ham&#39;</span><span class="p">,</span> <span class="nb">globals</span><span class="p">(),</span> <span class="nb">locals</span><span class="p">(),</span> <span class="p">[],</span> <span class="o">-</span><span class="mf">1</span><span class="p">)</span>
</pre></div>
</div>
<p>Note how <a title="__import__" class="reference internal" href="#__import__"><tt class="xref docutils literal"><span class="pre">__import__()</span></tt></a> returns the toplevel module here because this is
the object that is bound to a name by the <a class="reference external" href="../reference/simple_stmts.html#import"><tt class="xref docutils literal"><span class="pre">import</span></tt></a> statement.</p>
<p>On the other hand, the statement <tt class="docutils literal"><span class="pre">from</span> <span class="pre">spam.ham</span> <span class="pre">import</span> <span class="pre">eggs,</span> <span class="pre">sausage</span> <span class="pre">as</span>
<span class="pre">saus</span></tt> results in</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">_temp</span> <span class="o">=</span> <span class="nb">__import__</span><span class="p">(</span><span class="s">&#39;spam.ham&#39;</span><span class="p">,</span> <span class="nb">globals</span><span class="p">(),</span> <span class="nb">locals</span><span class="p">(),</span> <span class="p">[</span><span class="s">&#39;eggs&#39;</span><span class="p">,</span> <span class="s">&#39;sausage&#39;</span><span class="p">],</span> <span class="o">-</span><span class="mf">1</span><span class="p">)</span>
<span class="n">eggs</span> <span class="o">=</span> <span class="n">_temp</span><span class="o">.</span><span class="n">eggs</span>
<span class="n">saus</span> <span class="o">=</span> <span class="n">_temp</span><span class="o">.</span><span class="n">sausage</span>
</pre></div>
</div>
<p>Here, the <tt class="docutils literal"><span class="pre">spam.ham</span></tt> module is returned from <a title="__import__" class="reference internal" href="#__import__"><tt class="xref docutils literal"><span class="pre">__import__()</span></tt></a>.  From this
object, the names to import are retrieved and assigned to their respective
names.</p>
<p>If you simply want to import a module (potentially within a package) by name,
you can get it from <a title="sys.modules" class="reference external" href="sys.html#sys.modules"><tt class="xref docutils literal"><span class="pre">sys.modules</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">name</span> <span class="o">=</span> <span class="s">&#39;foo.bar.baz&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">__import__</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="go">&lt;module &#39;foo&#39; from ...&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">baz</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">modules</span><span class="p">[</span><span class="n">name</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">baz</span>
<span class="go">&lt;module &#39;foo.bar.baz&#39; from ...&gt;</span>
</pre></div>
</div>
<p>
<span class="versionmodified">Changed in version 2.5: </span>The level parameter was added.</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Keyword support for parameters was added.</p>
</dd></dl>

</div>
<div class="section" id="non-essential-built-in-functions">
<span id="non-essential-built-in-funcs"></span><h1>3. Non-essential Built-in Functions<a class="headerlink" href="#non-essential-built-in-functions" title="Permalink to this headline">¶</a></h1>
<p>There are several built-in functions that are no longer essential to learn, know
or use in modern Python programming.  They have been kept here to maintain
backwards compatibility with programs written for older versions of Python.</p>
<p>Python programmers, trainers, students and book writers should feel free to
bypass these functions without concerns about missing something important.</p>
<dl class="function">
<dt id="apply">
<tt class="descname">apply</tt><big>(</big><em>function</em>, <em>args</em><span class="optional">[</span>, <em>keywords</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#apply" title="Permalink to this definition">¶</a></dt>
<dd><p>The <em>function</em> argument must be a callable object (a user-defined or built-in
function or method, or a class object) and the <em>args</em> argument must be a
sequence.  The <em>function</em> is called with <em>args</em> as the argument list; the number
of arguments is the length of the tuple. If the optional <em>keywords</em> argument is
present, it must be a dictionary whose keys are strings.  It specifies keyword
arguments to be added to the end of the argument list. Calling <a title="apply" class="reference internal" href="#apply"><tt class="xref docutils literal"><span class="pre">apply()</span></tt></a> is
different from just calling <tt class="docutils literal"><span class="pre">function(args)</span></tt>, since in that case there is
always exactly one argument.  The use of <a title="apply" class="reference internal" href="#apply"><tt class="xref docutils literal"><span class="pre">apply()</span></tt></a> is equivalent to
<tt class="docutils literal"><span class="pre">function(*args,</span> <span class="pre">**keywords)</span></tt>.</p>
<p>
<span class="versionmodified">Deprecated since version 2.3: </span>Use the extended call syntax with <tt class="docutils literal"><span class="pre">*args</span></tt> and <tt class="docutils literal"><span class="pre">**keywords</span></tt> instead.</p>
</dd></dl>

<dl class="function">
<dt id="buffer">
<tt class="descname">buffer</tt><big>(</big><em>object</em><span class="optional">[</span>, <em>offset</em><span class="optional">[</span>, <em>size</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#buffer" title="Permalink to this definition">¶</a></dt>
<dd>The <em>object</em> argument must be an object that supports the buffer call interface
(such as strings, arrays, and buffers).  A new buffer object will be created
which references the <em>object</em> argument. The buffer object will be a slice from
the beginning of <em>object</em> (or from the specified <em>offset</em>). The slice will
extend to the end of <em>object</em> (or will have a length given by the <em>size</em>
argument).</dd></dl>

<dl class="function">
<dt id="coerce">
<tt class="descname">coerce</tt><big>(</big><em>x</em>, <em>y</em><big>)</big><a class="headerlink" href="#coerce" title="Permalink to this definition">¶</a></dt>
<dd>Return a tuple consisting of the two numeric arguments converted to a common
type, using the same rules as used by arithmetic operations. If coercion is not
possible, raise <a title="exceptions.TypeError" class="reference external" href="exceptions.html#exceptions.TypeError"><tt class="xref docutils literal"><span class="pre">TypeError</span></tt></a>.</dd></dl>

<dl class="function">
<dt id="intern">
<tt class="descname">intern</tt><big>(</big><em>string</em><big>)</big><a class="headerlink" href="#intern" title="Permalink to this definition">¶</a></dt>
<dd><p>Enter <em>string</em> in the table of &#8220;interned&#8221; strings and return the interned string
&#8211; which is <em>string</em> itself or a copy. Interning strings is useful to gain a
little performance on dictionary lookup &#8211; if the keys in a dictionary are
interned, and the lookup key is interned, the key comparisons (after hashing)
can be done by a pointer compare instead of a string compare.  Normally, the
names used in Python programs are automatically interned, and the dictionaries
used to hold module, class or instance attributes have interned keys.</p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>Interned strings are not immortal (like they used to be in Python 2.2 and
before); you must keep a reference to the return value of <a title="intern" class="reference internal" href="#intern"><tt class="xref docutils literal"><span class="pre">intern()</span></tt></a> around
to benefit from it.</p>
</dd></dl>

<p class="rubric">Footnotes</p>
<table class="docutils footnote" frame="void" id="id4" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>It is used relatively rarely so does not warrant being made into a statement.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id5" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td>Specifying a buffer size currently has no effect on systems that don&#8217;t have
<tt class="xref docutils literal"><span class="pre">setvbuf</span></tt>.  The interface to specify the buffer size is not done using a
method that calls <tt class="xref docutils literal"><span class="pre">setvbuf</span></tt>, because that may dump core when called after
any I/O has been performed, and there&#8217;s no reliable way to determine whether
this is the case.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td>In the current implementation, local variable bindings cannot normally be
affected this way, but variables retrieved from other scopes (such as modules)
can be.  This may change.</td></tr>
</tbody>
</table>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../contents.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">2. Built-in Functions</a></li>
<li><a class="reference external" href="#non-essential-built-in-functions">3. Non-essential Built-in Functions</a></li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="intro.html"
                                  title="previous chapter">1. Introduction</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="constants.html"
                                  title="next chapter">4. Built-in Constants</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/functions.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="constants.html" title="4. Built-in Constants"
             >next</a> |</li>
        <li class="right" >
          <a href="intro.html" title="1. Introduction"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
      Last updated on Apr 15, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>